Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
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);
     $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;
 }