Example #1
0
 /**
  * Returns data related to the scheduled items.
  *
  * @param  int  $p_prev
  * @param  int  $p_next
  * @return date
  */
 public static function GetPlayOrderRange($p_prev = 1, $p_next = 1)
 {
     if (!is_int($p_prev) || !is_int($p_next)) {
         //must enter integers to specify ranges
         Logging::info("Invalid range parameters: {$p_prev} or {$p_next}");
         return array();
     }
     $date = new Application_Common_DateHelper();
     $timeNow = $date->getTimestamp();
     $utcTimeNow = $date->getUtcTimestamp();
     $shows = Application_Model_Show::getPrevCurrentNext($utcTimeNow);
     $previousShowID = count($shows['previousShow']) > 0 ? $shows['previousShow'][0]['instance_id'] : null;
     $currentShowID = count($shows['currentShow']) > 0 ? $shows['currentShow'][0]['instance_id'] : null;
     $nextShowID = count($shows['nextShow']) > 0 ? $shows['nextShow'][0]['instance_id'] : null;
     $results = self::GetPrevCurrentNext($previousShowID, $currentShowID, $nextShowID, $utcTimeNow);
     $range = array("env" => APPLICATION_ENV, "schedulerTime" => $timeNow, "previous" => $results['previous'] != null ? $results['previous'] : (count($shows['previousShow']) > 0 ? $shows['previousShow'][0] : null), "current" => $results['current'] != null ? $results['current'] : (count($shows['currentShow']) > 0 && $shows['currentShow'][0]['record'] == 1 ? $shows['currentShow'][0] : null), "next" => $results['next'] != null ? $results['next'] : (count($shows['nextShow']) > 0 ? $shows['nextShow'][0] : null), "currentShow" => $shows['currentShow'], "nextShow" => $shows['nextShow'], "timezone" => date("T"), "timezoneOffset" => date("Z"));
     return $range;
 }
Example #2
0
 /**
  * Retrieve the currently playing show as well as upcoming shows.
  * Number of shows returned and the time interval in which to
  * get the next shows can be configured as GET parameters.
  *
  * TODO: in the future, make interval length a parameter instead of hardcode to 48
  *
  * Possible parameters:
  * type - Can have values of "endofday" or "interval". If set to "endofday",
  *        the function will retrieve shows from now to end of day.
  *        If set to "interval", shows in the next 48 hours will be retrived.
  *        Default is "interval".
  * limit - How many shows to retrieve
  *         Default is "5".
  */
 public function liveInfoAction()
 {
     if (Application_Model_Preference::GetAllow3rdPartyApi()) {
         // disable the view and the layout
         $this->view->layout()->disableLayout();
         $this->_helper->viewRenderer->setNoRender(true);
         $date = new Application_Common_DateHelper();
         $utcTimeNow = $date->getUtcTimestamp();
         $utcTimeEnd = "";
         // if empty, getNextShows will use interval instead of end of day
         $request = $this->getRequest();
         $type = $request->getParam('type');
         /* This is some *extremely* lazy programming that needs to bi fixed. For some reason
          * we are using two entirely different codepaths for very similar functionality (type = endofday
          * vs type = interval). Needs to be fixed for 2.3 - MK */
         if ($type == "endofday") {
             $limit = $request->getParam('limit');
             if ($limit == "" || !is_numeric($limit)) {
                 $limit = "5";
             }
             // make getNextShows use end of day
             $utcTimeEnd = Application_Common_DateHelper::GetDayEndTimestampInUtc();
             $result = array("env" => APPLICATION_ENV, "schedulerTime" => gmdate("Y-m-d H:i:s"), "currentShow" => Application_Model_Show::getCurrentShow($utcTimeNow), "nextShow" => Application_Model_Show::getNextShows($utcTimeNow, $limit, $utcTimeEnd));
             Application_Model_Show::convertToLocalTimeZone($result["currentShow"], array("starts", "ends", "start_timestamp", "end_timestamp"));
             Application_Model_Show::convertToLocalTimeZone($result["nextShow"], array("starts", "ends", "start_timestamp", "end_timestamp"));
         } else {
             $result = Application_Model_Schedule::GetPlayOrderRange();
             //Convert from UTC to localtime for Web Browser.
             Application_Model_Show::ConvertToLocalTimeZone($result["currentShow"], array("starts", "ends", "start_timestamp", "end_timestamp"));
             Application_Model_Show::ConvertToLocalTimeZone($result["nextShow"], array("starts", "ends", "start_timestamp", "end_timestamp"));
         }
         //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;
         header("Content-type: text/javascript");
         // If a callback is not given, then just provide the raw JSON.
         echo isset($_GET['callback']) ? $_GET['callback'] . '(' . json_encode($result) . ')' : json_encode($result);
     } else {
         header('HTTP/1.0 401 Unauthorized');
         print 'You are not allowed to access this resource. ';
         exit;
     }
 }
Example #3
0
    /**
     * Given time $timeNow, returns the show being played right now.
     * Times are all in UTC time.
     *
     * @param  String $timeNow - current time (in UTC)
     * @return array  - show being played right now
     */
    public static function getCurrentShow($timeNow = null)
    {
        global $CC_CONFIG;
        $con = Propel::getConnection();
        if ($timeNow == null) {
            $date = new Application_Common_DateHelper();
            $timeNow = $date->getUtcTimestamp();
        }
        //TODO, returning starts + ends twice (once with an alias). Unify this after the 2.0 release. --Martin
        $sql = <<<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_show_instances si
     LEFT JOIN cc_show s
     ON si.show_id = s.id
WHERE si.show_id = s.id
  AND si.starts <= :timeNow1::timestamp
  AND si.ends > :timeNow2::timestamp
  AND modified_instance != TRUE
SQL;
        $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;
    }