示例#1
0
function createTestShow($showNumber, $showTime, $duration = "1:00")
{
    $data = array();
    $strTime = $showTime->format("Y-m-d H:i");
    echo "Adding show: {$strTime}\n";
    $data['add_show_name'] = 'automated show ' . $showNumber;
    $data['add_show_start_date'] = $showTime->format("Y-m-d");
    $data['add_show_start_time'] = $showTime->format("H:i");
    $data['add_show_duration'] = $duration;
    $data['add_show_no_end'] = 0;
    $data['add_show_repeats'] = 0;
    $data['add_show_description'] = 'automated show';
    $data['add_show_url'] = 'http://www.OfirGal.com';
    $data['add_show_color'] = "";
    $data['add_show_genre'] = "Ofir";
    $data['add_show_background_color'] = "";
    $data['add_show_record'] = 0;
    $data['add_show_hosts'] = "";
    $showId = Application_Model_Show::create($data);
    //echo "show created, ID: $showId\n";
    // populating the show with a playlist
    $instances = Application_Model_Show::getShows($showTime, $showTime);
    $instance = array_pop($instances);
    $show = new Application_Model_ShowInstance($instance["instance_id"]);
    //echo "Adding playlist to show instance ".$show->getShowInstanceId()."\n";
    $show->scheduleShow(array(1));
    //echo "done\n";
    //$show->scheduleShow(array($playlist->getId()));
}
示例#2
0
 public static function SendMessageToShowRecorder($event_type)
 {
     $exchange = 'airtime-pypo';
     $now = new DateTime("@" . time());
     //in UTC timezone
     $end_timestamp = new DateTime("@" . (time() + 3600 * 2));
     //in UTC timezone
     $temp = array();
     $temp['event_type'] = $event_type;
     $temp['server_timezone'] = Application_Model_Preference::GetTimezone();
     if ($event_type == "update_recorder_schedule") {
         $temp['shows'] = Application_Model_Show::getShows($now, $end_timestamp, $onlyRecord = true);
     }
     $data = json_encode($temp);
     self::sendMessage($exchange, $data);
 }
示例#3
0
    public function resizeShow($deltaDay, $deltaMin)
    {
        $con = Propel::getConnection();
        $hours = $deltaMin / 60;
        $hours = $hours > 0 ? floor($hours) : ceil($hours);
        $mins = abs($deltaMin % 60);
        $today_timestamp = gmdate("Y-m-d H:i:s");
        $starts = $this->getShowInstanceStart();
        $ends = $this->getShowInstanceEnd();
        if (strtotime($today_timestamp) > strtotime($starts)) {
            return "can't resize a past show";
        }
        //$sql = "SELECT timestamp '{$ends}' + interval '{$deltaDay} days' + interval '{$hours}:{$mins}'";
        $sql = "SELECT timestamp :ends + interval :deltaDays + interval :deltaTime";
        $now_ends = Application_Common_Database::prepareAndExecute($sql, array(':ends' => $ends, ':deltaDays' => "{$deltaDay} days", ':deltaTime' => "{$hours}:{$mins}"), 'column');
        //only need to check overlap if show increased in size.
        if (strtotime($new_ends) > strtotime($ends)) {
            $utcStartDateTime = new DateTime($ends, new DateTimeZone("UTC"));
            $utcEndDateTime = new DateTime($new_ends, new DateTimeZone("UTC"));
            $overlap = Application_Model_Show::getShows($utcStartDateTime, $utcEndDateTime);
            if (count($overlap) > 0) {
                // TODO : fix ghetto error handling -- RG
                return "Should not overlap shows";
            }
        }
        //with overbooking no longer need to check already scheduled content still fits.
        //must update length of all rebroadcast instances.
        if ($this->isRecorded()) {
            $sql = <<<SQL
UPDATE cc_show_instances
SET ends = (ends + interval :deltaDays + interval :interval)
WHERE rebroadcast = 1
  AND instance_id = :instanceId;
SQL;
            Application_Common_Database::prepareAndExecute($sql, array(':deltaDays' => "{$deltaDay} days", ':interval' => "{$hours}:{$mins}", ':instanceId' => $this->_instanceId), 'execute');
        }
        $this->setShowEnd($new_ends);
        Application_Model_RabbitMq::PushSchedule();
    }
 public function recordedShowsAction()
 {
     $utcTimezone = new DateTimeZone("UTC");
     $nowDateTime = new DateTime("now", $utcTimezone);
     $endDateTime = clone $nowDateTime;
     $endDateTime = $endDateTime->add(new DateInterval("PT2H"));
     $this->view->shows = Application_Model_Show::getShows($nowDateTime, $endDateTime, $onlyRecord = true);
     $this->view->is_recording = false;
     $this->view->server_timezone = Application_Model_Preference::GetDefaultTimezone();
     $rows = Application_Model_Show::getCurrentShow();
     if (count($rows) > 0) {
         $this->view->is_recording = $rows[0]['record'] == 1;
     }
 }
示例#5
0
 public function hasBeenUpdatedSince($timestamp, $instances)
 {
     $outdated = false;
     $shows = Application_Model_Show::getShows($this->startDT, $this->endDT);
     $include = array();
     if ($this->opts["showFilter"] !== 0) {
         $include[] = $this->opts["showFilter"];
     } elseif ($this->opts["myShows"] === 1) {
         $include = $this->getUsersShows();
     }
     $currentInstances = array();
     foreach ($shows as $show) {
         if (empty($include) || in_array($show["show_id"], $include)) {
             $currentInstances[] = $show["instance_id"];
             if (isset($show["last_scheduled"])) {
                 $dt = new DateTime($show["last_scheduled"], new DateTimeZone("UTC"));
             } else {
                 $dt = new DateTime($show["created"], new DateTimeZone("UTC"));
             }
             //check if any of the shows have a more recent timestamp.
             $showTimeStamp = intval($dt->format("U"));
             if ($timestamp < $showTimeStamp) {
                 $outdated = true;
                 break;
             }
         }
     }
     //see if the displayed show instances have changed. (deleted,
     //empty schedule etc)
     if ($outdated === false && count($instances) !== count($currentInstances)) {
         Logging::debug("show instances have changed.");
         $outdated = true;
     }
     return $outdated;
 }
示例#6
0
 public function recordedShowsAction()
 {
     $today_timestamp = date("Y-m-d H:i:s");
     $now = new DateTime($today_timestamp);
     $end_timestamp = $now->add(new DateInterval("PT2H"));
     $end_timestamp = $end_timestamp->format("Y-m-d H:i:s");
     $this->view->shows = Application_Model_Show::getShows(Application_Common_DateHelper::ConvertToUtcDateTime($today_timestamp, date_default_timezone_get()), Application_Common_DateHelper::ConvertToUtcDateTime($end_timestamp, date_default_timezone_get()), $onlyRecord = true);
     $this->view->is_recording = false;
     $this->view->server_timezone = Application_Model_Preference::GetTimezone();
     $rows = Application_Model_Show::getCurrentShow($today_timestamp);
     Application_Model_Show::convertToLocalTimeZone($rows, array("starts", "ends", "start_timestamp", "end_timestamp"));
     if (count($rows) > 0) {
         $this->view->is_recording = $rows[0]['record'] == 1;
     }
 }
示例#7
0
 /**
  *
  * @param DateTime $start
  *          -in UTC time
  * @param DateTime $end
  *          -in UTC time
  * @param boolean $editable
  */
 public static function &getFullCalendarEvents($p_start, $p_end, $p_editable = false)
 {
     $events = array();
     $interval = $p_start->diff($p_end);
     $days = $interval->format('%a');
     $shows = Application_Model_Show::getShows($p_start, $p_end);
     $content_count = Application_Model_ShowInstance::getContentCount($p_start, $p_end);
     $isFull = Application_Model_ShowInstance::getIsFull($p_start, $p_end);
     $displayTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
     $utcTimezone = new DateTimeZone("UTC");
     $now = new DateTime("now", $utcTimezone);
     foreach ($shows as &$show) {
         $options = array();
         //only bother calculating percent for week or day view.
         if (intval($days) <= 7) {
             $options["percent"] = Application_Model_Show::getPercentScheduled($show["starts"], $show["ends"], $show["time_filled"]);
         }
         if (isset($show["parent_starts"])) {
             $parentStartsDT = new DateTime($show["parent_starts"], $utcTimezone);
         }
         $startsDT = DateTime::createFromFormat("Y-m-d G:i:s", $show["starts"], $utcTimezone);
         $endsDT = DateTime::createFromFormat("Y-m-d G:i:s", $show["ends"], $utcTimezone);
         if ($p_editable) {
             if ($show["record"] && $now > $startsDT) {
                 $options["editable"] = false;
             } elseif ($show["rebroadcast"] && $now > $parentStartsDT) {
                 $options["editable"] = false;
             } elseif ($now < $endsDT) {
                 $options["editable"] = true;
             }
         }
         $startsDT->setTimezone($displayTimezone);
         $endsDT->setTimezone($displayTimezone);
         $options["show_empty"] = array_key_exists($show['instance_id'], $content_count) ? 0 : 1;
         if (array_key_exists($show['instance_id'], $isFull)) {
             $options["show_partial_filled"] = !$isFull[$show['instance_id']];
         } else {
             $options["show_partial_filled"] = true;
         }
         $event = array();
         $event["id"] = intval($show["instance_id"]);
         $event["title"] = $show["name"];
         $event["start"] = $startsDT->format("Y-m-d H:i:s");
         $event["end"] = $endsDT->format("Y-m-d H:i:s");
         $event["allDay"] = false;
         $event["showId"] = intval($show["show_id"]);
         $event["linked"] = intval($show["linked"]);
         $event["record"] = intval($show["record"]);
         $event["rebroadcast"] = intval($show["rebroadcast"]);
         $event["soundcloud_id"] = is_null($show["soundcloud_id"]) ? -1 : $show["soundcloud_id"];
         //for putting the now playing icon on the show.
         if ($now > $startsDT && $now < $endsDT) {
             $event["nowPlaying"] = true;
         } else {
             $event["nowPlaying"] = false;
         }
         //event colouring
         if ($show["color"] != "") {
             $event["textColor"] = "#" . $show["color"];
         }
         if ($show["background_color"] != "") {
             $event["color"] = "#" . $show["background_color"];
         }
         foreach ($options as $key => $value) {
             $event[$key] = $value;
         }
         $events[] = $event;
     }
     return $events;
 }
示例#8
0
文件: Show.php 项目: nidzix/Airtime
 /**
  *
  * @param DateTime $start
  *          -in UTC time
  * @param DateTime $end
  *          -in UTC time
  * @param boolean $editable
  */
 public static function &getFullCalendarEvents($p_start, $p_end, $p_editable = false)
 {
     $events = array();
     $interval = $p_start->diff($p_end);
     $days = $interval->format('%a');
     $shows = Application_Model_Show::getShows($p_start, $p_end);
     $nowEpoch = time();
     $content_count = Application_Model_ShowInstance::getContentCount($p_start, $p_end);
     $timezone = date_default_timezone_get();
     foreach ($shows as $show) {
         $options = array();
         //only bother calculating percent for week or day view.
         if (intval($days) <= 7) {
             $options["percent"] = Application_Model_Show::getPercentScheduled($show["starts"], $show["ends"], $show["time_filled"]);
         }
         $utc = new DateTimeZone("UTC");
         if (isset($show["parent_starts"])) {
             $parentStartsDT = new DateTime($show["parent_starts"], $utc);
             $parentStartsEpoch = intval($parentStartsDT->format("U"));
         }
         $startsDT = DateTime::createFromFormat("Y-m-d G:i:s", $show["starts"], $utc);
         $endsDT = DateTime::createFromFormat("Y-m-d G:i:s", $show["ends"], $utc);
         $startsEpochStr = $startsDT->format("U");
         $endsEpochStr = $endsDT->format("U");
         $startsEpoch = intval($startsEpochStr);
         $endsEpoch = intval($endsEpochStr);
         $startsDT->setTimezone(new DateTimeZone($timezone));
         $endsDT->setTimezone(new DateTimeZone($timezone));
         if ($p_editable) {
             if ($show["record"] && $nowEpoch > $startsEpoch) {
                 $options["editable"] = false;
             } elseif ($show["rebroadcast"] && $nowEpoch > $parentStartsEpoch) {
                 $options["editable"] = false;
             } elseif ($nowEpoch < $endsEpoch) {
                 $options["editable"] = true;
             }
         }
         $showInstance = new Application_Model_ShowInstance($show["instance_id"]);
         $options["show_empty"] = array_key_exists($show['instance_id'], $content_count) ? 0 : 1;
         $events[] =& self::makeFullCalendarEvent($show, $options, $startsDT, $endsDT, $startsEpochStr, $endsEpochStr);
     }
     return $events;
 }
 public function getShowList($startDT, $endDT)
 {
     $user = Application_Model_User::getCurrentUser();
     $shows = Application_Model_Show::getShows($startDT, $endDT);
     Logging::info($startDT->format("Y-m-d H:i:s"));
     Logging::info($endDT->format("Y-m-d H:i:s"));
     Logging::info($shows);
     //need to filter the list to only their shows
     if ($user->isHost()) {
         $showIds = array();
         foreach ($shows as $show) {
             $showIds[] = $show["show_id"];
         }
         $showIds = array_unique($showIds);
         Logging::info($showIds);
         $hostRecords = CcShowHostsQuery::create()->filterByDbHost($user->getId())->filterByDbShow($showIds)->find($this->con);
         $filteredShowIds = array();
         foreach ($hostRecords as $record) {
             $filteredShowIds[] = $record->getDbShow();
         }
         Logging::info($filteredShowIds);
         $filteredShows = array();
         foreach ($shows as $show) {
             if (in_array($show["show_id"], $filteredShowIds)) {
                 $filteredShows[] = $show;
             }
         }
     } else {
         $filteredShows = $shows;
     }
     $timezoneUTC = new DateTimeZone("UTC");
     $timezoneLocal = new DateTimeZone($this->timezone);
     foreach ($filteredShows as &$result) {
         //need to display the results in the station's timezone.
         $dateTime = new DateTime($result["starts"], $timezoneUTC);
         $dateTime->setTimezone($timezoneLocal);
         $result["starts"] = $dateTime->format("Y-m-d H:i:s");
         $dateTime = new DateTime($result["ends"], $timezoneUTC);
         $dateTime->setTimezone($timezoneLocal);
         $result["ends"] = $dateTime->format("Y-m-d H:i:s");
     }
     return $filteredShows;
 }