diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 76ee2b5f5..4dce47a29 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -382,7 +382,7 @@ class ApiController extends Zend_Controller_Action $this->view->is_recording = false; $this->view->server_timezone = Application_Model_Preference::GetTimezone(); - $rows = Application_Model_Show::GetCurrentShow($today_timestamp); + $rows = Application_Model_Show::getCurrentShow($today_timestamp); Application_Model_Show::convertToLocalTimeZone($rows, array("starts", "ends", "start_timestamp", "end_timestamp")); if (count($rows) > 0) { @@ -928,7 +928,7 @@ class ApiController extends Zend_Controller_Action } } elseif ($djtype == "dj") { //check against show dj auth - $showInfo = Application_Model_Show::GetCurrentShow(); + $showInfo = Application_Model_Show::getCurrentShow(); // there is current playing show if (isset($showInfo[0]['id'])) { $current_show_id = $showInfo[0]['id']; diff --git a/airtime_mvc/application/controllers/DashboardController.php b/airtime_mvc/application/controllers/DashboardController.php index 719899fb1..026468563 100644 --- a/airtime_mvc/application/controllers/DashboardController.php +++ b/airtime_mvc/application/controllers/DashboardController.php @@ -24,7 +24,7 @@ class DashboardController extends Zend_Controller_Action $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); - $show = Application_Model_Show::GetCurrentShow(); + $show = Application_Model_Show::getCurrentShow(); $show_id = isset($show['id'])?$show['id']:0; @@ -51,7 +51,7 @@ class DashboardController extends Zend_Controller_Action $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); - $show = Application_Model_Show::GetCurrentShow(); + $show = Application_Model_Show::getCurrentShow(); $show_id = isset($show[0]['id'])?$show[0]['id']:0; $source_connected = Application_Model_Preference::GetSourceStatus($sourcename); diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index f79e10805..58c2db1de 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -121,7 +121,7 @@ class ScheduleController extends Zend_Controller_Action public function getCurrentShowAction() { - $currentShow = Application_Model_Show::GetCurrentShow(); + $currentShow = Application_Model_Show::getCurrentShow(); if (!empty($currentShow)) { $this->view->si_id = $currentShow[0]["instance_id"]; $this->view->current_show = true; @@ -346,7 +346,7 @@ class ScheduleController extends Zend_Controller_Action public function getCurrentPlaylistAction() { $range = Application_Model_Schedule::GetPlayOrderRange(); - $show = Application_Model_Show::GetCurrentShow(); + $show = Application_Model_Show::getCurrentShow(); /* Convert all UTC times to localtime before sending back to user. */ if (isset($range["previous"])) { diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 5e5faad44..046b95739 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -1788,7 +1788,7 @@ class Application_Model_Show * @param String $timeNow - current time (in UTC) * @return array - show being played right now */ - public static function GetCurrentShow($timeNow=null) + public static function getCurrentShow($timeNow=null) { global $CC_CONFIG; $con = Propel::getConnection(); @@ -1797,16 +1797,34 @@ class Application_Model_Show $timeNow = $date->getUtcTimestamp(); } //TODO, returning starts + ends twice (once with an alias). Unify this after the 2.0 release. --Martin - $sql = "SELECT si.starts as start_timestamp, si.ends as end_timestamp, s.name," - ." s.id, si.id as instance_id, si.record, s.url, starts, ends" - ." FROM $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] s" - ." WHERE si.show_id = s.id" - ." AND si.starts <= TIMESTAMP '$timeNow'" - ." AND si.ends > TIMESTAMP '$timeNow'" - ." AND modified_instance != TRUE"; + $sql = << TIMESTAMP ':timeNow2' + AND modified_instance != TRUE" +SQL; - // Convert back to local timezone - $rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC); + $stmt = $con->prepare($sql); + $stmt->bindParam(':timeNow1', $timeNow); + $stmt->bindParam(':timeNow2', $timeNow); + + if ($stmt->execute()) { + $rows = $stmt->fetchAll(); + } else { + $msg = implode(',', $stmt->errorInfo()); + throw new Exception("Error: $msg"); + } return $rows; } @@ -1819,17 +1837,38 @@ class Application_Model_Show { global $CC_CONFIG; $con = Propel::getConnection(); + // //TODO, returning starts + ends twice (once with an alias). Unify this after the 2.0 release. --Martin - $sql = "SELECT si.starts as start_timestamp, si.ends as end_timestamp, s.name," - ." s.id, si.id as instance_id, si.record, s.url, starts, ends" - ." FROM $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] s" - ." WHERE si.show_id = s.id" - ." AND si.starts > TIMESTAMP '$p_timeNow' - INTERVAL '2 days'" - ." AND si.ends < TIMESTAMP '$p_timeNow' + INTERVAL '2 days'" - ." AND modified_instance != TRUE" - ." ORDER BY si.starts"; + $sql = << TIMESTAMP ':timeNow1' - INTERVAL '2 days' + AND si.ends < TIMESTAMP ':timeNow2' + INTERVAL '2 days' + AND modified_instance != TRUE +ORDER BY si.starts +SQL; + + $stmt = $con->prepare($sql); + $stmt->bindParam(':timeNow1', $p_timeNow); + $stmt->bindParam(':timeNow2', $p_timeNow); + + if ($stmt->execute()) { + $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); + } else { + $msg = implode(',', $stmt->errorInfo()); + throw new Exception("Error: $msg"); + } - $rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC); $numberOfRows = count($rows); $results['previousShow'] = array(); @@ -1923,7 +1962,7 @@ class Application_Model_Show * @param String $timeEnd - interval end time (in UTC) * @return array - the next $limit number of shows within the time interval */ - public static function getNextShows($timeStart, $limit = "0", $timeEnd = "") + public static function getNextShows($timeStart, $limit = "ALL", $timeEnd = "") { global $CC_CONFIG; $con = Propel::getConnection(); @@ -1937,21 +1976,38 @@ class Application_Model_Show } //TODO, returning starts + ends twice (once with an alias). Unify this after the 2.0 release. --Martin - $sql = "SELECT si.starts as start_timestamp, si.ends as end_timestamp, s.name, s.id, si.id as instance_id, si.record, s.url, starts, ends FROM" - ." $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] s" - ." WHERE si.show_id = s.id" - ." AND si.starts >= TIMESTAMP '$timeStart'" - ." AND si.starts < TIMESTAMP $timeEnd" - ." AND modified_instance != TRUE" - ." ORDER BY si.starts"; + $sql = <<= TIMESTAMP ':timeStart' + AND si.starts < TIMESTAMP ':timeEnd' + AND modified_instance != TRUE +ORDER BY si.starts +LIMIT :lim +SQL; - // defaults to retrieve all shows within the interval if $limit not set - if ($limit != "0") { - $sql = $sql . " LIMIT $limit"; + $stmt = $con->prepare($sql); + $stmt->bindParam(':timeStart', $timeStart); + $stmt->bindParam(':timeEnd', $timeEnd); + $stmt->bindParam(':lim', $limit); + + if ($stmt->execute()) { + $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); + } else { + $msg = implode(',', $stmt->errorInfo()); + throw new Exception("Error: $msg"); } - $rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC); - return $rows; } @@ -1981,6 +2037,7 @@ class Application_Model_Show global $CC_CONFIG; $con = Propel::getConnection(); + //Not using prepared statement here since not using an variable input. $sql = "SELECT column_name, character_maximum_length FROM information_schema.columns" ." WHERE table_name = 'cc_show' AND character_maximum_length > 0"; $result = $con->query($sql)->fetchAll();