SAAS-870: Schedule widget displays shows in wrong timezone

Have angularjs hooked in
This commit is contained in:
drigato 2015-06-26 15:25:44 -04:00
parent c79e4fb9ea
commit 0a4651f752
4 changed files with 143 additions and 67 deletions

View file

@ -61,11 +61,9 @@ class WidgetHelper
// Removing "next" days and creating two weekly arrays // Removing "next" days and creating two weekly arrays
public static function getWeekInfoV2($timezone) public static function getWeekInfoV2($timezone)
{ {
//weekStart is in station time.
//$weekStartDateTime = Application_Common_DateHelper::getWeekStartDateTime();
$weekStartDateTime = new DateTime("now", new DateTimeZone(Application_Model_Preference::GetTimezone())); $weekStartDateTime = new DateTime("now", new DateTimeZone(Application_Model_Preference::GetTimezone()));
$maxNumOFWeeks = 2; //$maxNumOFWeeks = 2;
$result = array(); $result = array();
@ -84,50 +82,57 @@ class WidgetHelper
// a time of "00:00". $utcDayStart is used below when querying for shows. // a time of "00:00". $utcDayStart is used below when querying for shows.
$utcDayStartDT = clone $weekStartDateTime; $utcDayStartDT = clone $weekStartDateTime;
$utcDayStartDT->setTime(0, 0, 0); $utcDayStartDT->setTime(0, 0, 0);
$utcDayStart = $utcDayStartDT->format(DEFAULT_TIMESTAMP_FORMAT);
$weekCounter = 0;
while ($weekCounter < $maxNumOFWeeks) {
for ($dayOfWeekCounter = 0; $dayOfWeekCounter < DAYS_PER_WEEK; $dayOfWeekCounter++) {
$dateParse = date_parse($weekStartDateTime->format(DEFAULT_TIMESTAMP_FORMAT));
$result[$weekCounter][$dayOfWeekCounter]["dayOfMonth"] = $dateParse["day"]; $utcDayStart = $utcDayStartDT->format("Y-m-d H:i:s");
$result[$weekCounter][$dayOfWeekCounter]["dayOfWeek"] = strtoupper(date("D", $weekStartDateTime->getTimestamp())); //$weekCounter = 0;
//while ($weekCounter < $maxNumOFWeeks) {
//have to be in station timezone when adding 1 day for daylight savings. Logging::info($utcDayStart);
$weekStartDateTime->setTimezone(new DateTimeZone($timezone)); for ($dayOfWeekCounter = 0; $dayOfWeekCounter < DAYS_PER_WEEK; $dayOfWeekCounter++) {
$weekStartDateTime->add(new DateInterval('P1D')); $dateParse = date_parse($weekStartDateTime->format("Y-m-d H:i:s"));
//convert back to UTC to get the actual timestamp used for search. $result["scheduleData"][$weekStartDateTime->getTimestamp()] = array();
$weekStartDateTime->setTimezone($utcTimezone); $result["scheduleData"][$weekStartDateTime->getTimestamp()]["dayOfMonth"] = $dateParse["day"];
$result["scheduleData"][$weekStartDateTime->getTimestamp()]["dayOfWeek"] = strtoupper(date("D", $weekStartDateTime->getTimestamp()));
// When querying for shows we need the start and end date range to have //have to be in station timezone when adding 1 day for daylight savings.
// a time of "00:00". $weekStartDateTime->setTimezone(new DateTimeZone($timezone));
$utcDayEndDT = clone $weekStartDateTime; $weekStartDateTime->add(new DateInterval('P1D'));
$utcDayEndDT->setTime(0, 0, 0);
$utcDayEnd = $utcDayEndDT->format(DEFAULT_TIMESTAMP_FORMAT);
$shows = Application_Model_Show::getNextShows($utcDayStart, "ALL", $utcDayEnd);
$utcDayStart = $utcDayEnd;
// convert to user-defined timezone, or default to station //convert back to UTC to get the actual timestamp used for search.
Application_Common_DateHelper::convertTimestampsToTimezone( $weekStartDateTime->setTimezone($utcTimezone);
$shows,
array("starts", "ends", "start_timestamp", "end_timestamp"),
$timezone
);
foreach($shows as &$show) {
$startParseDate = date_parse($show['starts']);
$show["show_start_hour"] = str_pad($startParseDate["hour"], 2, "0", STR_PAD_LEFT).":".str_pad($startParseDate["minute"], 2, 0, STR_PAD_LEFT);
$endParseDate = date_parse($show['ends']);
$show["show_end_hour"] = str_pad($endParseDate["hour"], 2, 0, STR_PAD_LEFT).":".str_pad($endParseDate["minute"],2, 0, STR_PAD_LEFT);
}
$result[$weekCounter][$dayOfWeekCounter]["shows"] = $shows;
}
$weekCounter += 1;
} }
Logging::info($weekStartDateTime->format("Y-m-d H:i:s"));
// When querying for shows we need the start and end date range to have
// a time of "00:00".
/*$utcDayEndDT = clone $weekStartDateTime;
$utcDayEndDT->setTime(0, 0, 0);
$utcDayEnd = $utcDayEndDT->format("Y-m-d H:i:s");
$shows = Application_Model_Show::getNextShows($utcDayStart, "ALL", $utcDayEnd);
$utcDayStart = $utcDayEnd;
// convert to user-defined timezone, or default to station
/*Application_Common_DateHelper::convertTimestampsToTimezone(
$shows,
array("starts", "ends", "start_timestamp", "end_timestamp"),
$timezone
);*/
/*foreach($shows as &$show) {
$startParseDate = date_parse($show['starts']);
$show["show_start_hour"] = str_pad($startParseDate["hour"], 2, "0", STR_PAD_LEFT).":".str_pad($startParseDate["minute"], 2, 0, STR_PAD_LEFT);
$endParseDate = date_parse($show['ends']);
$show["show_end_hour"] = str_pad($endParseDate["hour"], 2, 0, STR_PAD_LEFT).":".str_pad($endParseDate["minute"],2, 0, STR_PAD_LEFT);
}
//$result[$weekCounter][$dayOfWeekCounter]["shows"] = $shows;
array_push($result, $shows);*/
//}
//$weekCounter += 1;
//}
// XSS exploit prevention // XSS exploit prevention

View file

@ -98,7 +98,8 @@ class EmbedController extends Zend_Controller_Action
$weeklyScheduleData = WidgetHelper::getWeekInfoV2($this->getRequest()->getParam("timezone")); $weeklyScheduleData = WidgetHelper::getWeekInfoV2($this->getRequest()->getParam("timezone"));
// Return only the current week's schedule data. In the future we may use the next week's data. // Return only the current week's schedule data. In the future we may use the next week's data.
$this->view->weeklyScheduleData = ($weeklyScheduleData[0]); $this->view->schedule_data = json_encode($weeklyScheduleData);
$this->view->weeklyScheduleData = $weeklyScheduleData;
$currentDay = new DateTime("now", new DateTimeZone(Application_Model_Preference::GetTimezone())); $currentDay = new DateTime("now", new DateTimeZone(Application_Model_Preference::GetTimezone()));
//day of the month without leading zeros (1 to 31) //day of the month without leading zeros (1 to 31)

View file

@ -2,13 +2,20 @@
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.js" type="text/javascript"></script>
<link rel="stylesheet" href="<?php echo $this->css?>" type="text/css"> <link rel="stylesheet" href="<?php echo $this->css?>" type="text/css">
<script src="<?php echo $this->jquery ?>" type="text/javascript"></script> <script src="<?php echo $this->jquery ?>" type="text/javascript"></script>
<link href='https://fonts.googleapis.com/css?family=Roboto:400,100,300,700' rel='stylesheet' type='text/css'> <link href='https://fonts.googleapis.com/css?family=Roboto:400,100,300,700' rel='stylesheet' type='text/css'>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
//initialize first day to active
$('.tabs').find("li").first().addClass("active");
$('.schedule_content').find('.schedule_item').first().addClass("active");
$('.tabs li').click(function(){ $('.tabs li').click(function(){
var tab_id = $(this).attr('data-tab'); //var tab_id = $(this).attr('data-tab');
var tab_id = "day-"+$(this).find('span').text();
$('.tabs li').removeClass('active'); $('.tabs li').removeClass('active');
$('.schedule_item').removeClass('active'); $('.schedule_item').removeClass('active');
@ -18,38 +25,37 @@
}); });
}); });
var schedule_data = <?php echo $this->schedule_data; ?>;
console.log(schedule_data);
var app = angular.module('scheduleWidget', []);
app.controller('scheduleController', ['$scope', '$window', function($scope, $window) {
$scope.schedule_data = $window.schedule_data["scheduleData"];
$scope.isEmpty = function(obj) {
return obj.length == 0;
};
}]);
</script> </script>
</head> </head>
<body> <body ng-app="scheduleWidget" ng-controller="scheduleController">
<div class="schedule tab_content current"> <div class="schedule tab_content current">
<ul class="tabs"> <ul class="tabs">
<?php <li ng-repeat="x in schedule_data track by $index">
foreach($this->weeklyScheduleData as $day => $data) { {{x.dayOfWeek}}<span>{{x.dayOfMonth}}</span>
$activeClass = $this->currentDayOfMonth == $data["dayOfMonth"] ? "active" : ""; </li>
echo "<li class='".$activeClass."' data-tab='day-".$data["dayOfMonth"]."'>" . $data["dayOfWeek"] . "<span>" . $data["dayOfMonth"] . "</span></li>";
}?>
</ul> </ul>
<div class="schedule_content"> <div class="schedule_content">
<?php <div ng-repeat="x in schedule_data track by $index" ng-attr-id="{{'day-' + x.dayOfMonth}}" class="schedule_item">
foreach($this->weeklyScheduleData as $day => $data) { <div ng-if="isEmpty(x.shows)" class="row empty-schedule">Looks like there are no shows scheduled on this day.</div>
$activeClass = $this->currentDayOfMonth == $data["dayOfMonth"] ? "active" : ""; <div ng-repeat="show in x.shows" class="row">
<div class="time_grid">{{show.show_start_hour}} - {{show.show_end_hour}}</div>
echo "<div id='day-".$data["dayOfMonth"]."' class='schedule_item ".$activeClass."'>"; <div class="name_grid">{{show.name}}</div>
if (count($data["shows"]) == 0) { </div>
echo "<div class='row empty-schedule'>Looks like there are no shows scheduled on this day.</div>"; </div>
} else {
foreach ($data["shows"] as $show => $showData) {
echo "<div class='row'>";
echo "<div class='time_grid'>" . $showData["show_start_hour"] . ' - ' . $showData["show_end_hour"] . "</div>";
echo "<div class='name_grid'>" . $showData["name"] . "</div>";
echo "</div>";
}
}
echo "</div>";
}?>
</div> </div>
<div class="weekly-schedule-widget-footer" <?php if ($this->widgetStyle == "premium") echo "style='display:none'"; ?>> <div class="weekly-schedule-widget-footer" <?php if ($this->widgetStyle == "premium") echo "style='display:none'"; ?>>

View file

@ -0,0 +1,64 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="<?php echo $this->css?>" type="text/css">
<script src="<?php echo $this->jquery ?>" type="text/javascript"></script>
<link href='https://fonts.googleapis.com/css?family=Roboto:400,100,300,700' rel='stylesheet' type='text/css'>
<script type="text/javascript">
$(document).ready(function() {
$('.tabs li').click(function(){
var tab_id = $(this).attr('data-tab');
$('.tabs li').removeClass('active');
$('.schedule_item').removeClass('active');
$(this).addClass('active');
$("#"+tab_id).addClass('active');
});
});
</script>
</head>
<body>
<div class="schedule tab_content current">
<ul class="tabs">
<?php
foreach($this->weeklyScheduleData as $day => $data) {
$activeClass = $this->currentDayOfMonth == $data["dayOfMonth"] ? "active" : "";
echo "<li class='".$activeClass."' data-tab='day-".$data["dayOfMonth"]."'>" . $data["dayOfWeek"] . "<span>" . $data["dayOfMonth"] . "</span></li>";
}?>
</ul>
<div class="schedule_content">
<?php
foreach($this->weeklyScheduleData as $day => $data) {
$activeClass = $this->currentDayOfMonth == $data["dayOfMonth"] ? "active" : "";
echo "<div id='day-".$data["dayOfMonth"]."' class='schedule_item ".$activeClass."'>";
if (count($data["shows"]) == 0) {
echo "<div class='row empty-schedule'>Looks like there are no shows scheduled on this day.</div>";
} else {
foreach ($data["shows"] as $show => $showData) {
echo "<div class='row'>";
echo "<div class='time_grid'>" . $showData["show_start_hour"] . ' - ' . $showData["show_end_hour"] . "</div>";
echo "<div class='name_grid'>" . $showData["name"] . "</div>";
echo "</div>";
}
}
echo "</div>";
}?>
</div>
<div class="weekly-schedule-widget-footer" <?php if ($this->widgetStyle == "premium") echo "style='display:none'"; ?>>
<a href="https://airtime.pro" target="_blank">Powered by <span>Airtime Pro</span></a>
</div>
</div>
</body>
</html>