Removed repeated code

This commit is contained in:
Jamie Connor 2013-09-07 14:52:45 +12:00
parent 03f383f764
commit 6da9b6bf42
1 changed files with 25 additions and 36 deletions

View File

@ -315,44 +315,33 @@ class ApiController extends Zend_Controller_Action
$result = array();
if(isset($_GET['number_of_days'])){ //allows for schedule to be returned for multiple days
for ($i=0; $i<$number_of_days; $i++) {
$utcDayEnd = Application_Common_DateHelper::GetDayEndTimestamp($utcDayStart);
$shows = Application_Model_Show::getNextShows($utcDayStart, "ALL", $utcDayEnd);
$utcDayStart = $utcDayEnd;
Application_Model_Show::convertToLocalTimeZone($shows,
array("starts", "ends", "start_timestamp",
"end_timestamp"));
$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;
Application_Model_Show::convertToLocalTimeZone($shows,
array("starts", "ends", "start_timestamp",
"end_timestamp"));
$request = $this->getRequest();
$days = $request->getParam('days');
if (empty($days)) {$days = 7;}
for ($i=0; $i<$days; $i++) {
$utcDayEnd = Application_Common_DateHelper::GetDayEndTimestamp($utcDayStart);
$shows = Application_Model_Show::getNextShows($utcDayStart, "ALL", $utcDayEnd);
$utcDayStart = $utcDayEnd;
Application_Model_Show::convertToLocalTimeZone($shows,
array("starts", "ends", "start_timestamp",
"end_timestamp"));
if ($days==7) { //return with day of week index - standard
$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"]);
}
}
}
else{ //return with number index - days has been specified
$result[$i] = $shows;
}
}
// XSS exploit prevention
for ($i=0; $i<$days; $i++) {
foreach ($result[$i] as &$show) {
$show["name"] = htmlspecialchars($show["name"]);
$show["url"] = htmlspecialchars($show["url"]);
}
}