added optional parameter number_of_days for getting schedule information

This commit is contained in:
Jamie Connor 2013-08-26 11:26:09 +12:00
parent 2a0c9769aa
commit b1e71e5adf
1 changed files with 39 additions and 17 deletions

View File

@ -299,7 +299,7 @@ class ApiController extends Zend_Controller_Action
} }
} }
public function weekInfoAction() public function weekInfoAction()
{ {
if (Application_Model_Preference::GetAllow3rdPartyApi()) { if (Application_Model_Preference::GetAllow3rdPartyApi()) {
// disable the view and the layout // disable the view and the layout
@ -314,25 +314,47 @@ class ApiController extends Zend_Controller_Action
"saturday", "sunday"); "saturday", "sunday");
$result = array(); $result = array();
for ($i=0; $i<7; $i++) {
$utcDayEnd = Application_Common_DateHelper::GetDayEndTimestamp($utcDayStart); if(isset($_GET['number_of_days'])){ //allows for schedule to be returned for multiple days
$shows = Application_Model_Show::getNextShows($utcDayStart, "ALL", $utcDayEnd); for ($i=0; $i<$number_of_days; $i++) {
$utcDayStart = $utcDayEnd; $utcDayEnd = Application_Common_DateHelper::GetDayEndTimestamp($utcDayStart);
$shows = Application_Model_Show::getNextShows($utcDayStart, "ALL", $utcDayEnd);
$utcDayStart = $utcDayEnd;
Application_Model_Show::convertToLocalTimeZone($shows, Application_Model_Show::convertToLocalTimeZone($shows,
array("starts", "ends", "start_timestamp", array("starts", "ends", "start_timestamp",
"end_timestamp")); "end_timestamp"));
$result[$dow[$i]] = $shows; $result[$i] = $shows;
} }
// XSS exploit prevention
for ($i=0; $i<$number_of_days; $i++) {
foreach ($result[$i] as &$show) {
$show["name"] = htmlspecialchars($show["name"]);
$show["url"] = htmlspecialchars($show["url"]);
}
}
}else{
for ($i=0; $i<7; $i++) {
$utcDayEnd = Application_Common_DateHelper::GetDayEndTimestamp($utcDayStart);
$shows = Application_Model_Show::getNextShows($utcDayStart, "ALL", $utcDayEnd);
$utcDayStart = $utcDayEnd;
// XSS exploit prevention Application_Model_Show::convertToLocalTimeZone($shows,
foreach ($dow as $d) { array("starts", "ends", "start_timestamp",
foreach ($result[$d] as &$show) { "end_timestamp"));
$show["name"] = htmlspecialchars($show["name"]);
$show["url"] = htmlspecialchars($show["url"]); $result[$dow[$i]] = $shows;
} }
} // XSS exploit prevention
foreach ($dow as $d) {
foreach ($result[$d] as &$show) {
$show["name"] = htmlspecialchars($show["name"]);
$show["url"] = htmlspecialchars($show["url"]);
}
}
}
//used by caller to determine if the airtime they are running or widgets in use is out of date. //used by caller to determine if the airtime they are running or widgets in use is out of date.
$result['AIRTIME_API_VERSION'] = AIRTIME_API_VERSION; $result['AIRTIME_API_VERSION'] = AIRTIME_API_VERSION;