2015-03-15 18:13:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Schedule extends ModelBase
|
|
|
|
{
|
2015-03-30 19:18:42 +00:00
|
|
|
public function isEnabled() {
|
|
|
|
return $this->has('SCHEDULE');
|
|
|
|
}
|
|
|
|
|
2015-04-01 19:03:21 +00:00
|
|
|
private function isRoomFiltered($room)
|
|
|
|
{
|
|
|
|
if(!$this->has('SCHEDULE.ROOMFILTER'))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$rooms = $this->get('SCHEDULE.ROOMFILTER');
|
|
|
|
return !in_array($room, $rooms);
|
|
|
|
}
|
|
|
|
|
2015-03-15 18:13:25 +00:00
|
|
|
public function getSimulationOffset() {
|
|
|
|
return $this->get('SCHEDULE.SIMULATE_OFFSET', 0);
|
|
|
|
}
|
2015-03-30 14:20:30 +00:00
|
|
|
|
2015-03-30 19:18:42 +00:00
|
|
|
public function getScale() {
|
2015-03-31 15:16:40 +00:00
|
|
|
return floatval($this->get('SCHEDULE.SCALE', 7));
|
2015-03-30 14:20:30 +00:00
|
|
|
}
|
|
|
|
|
2015-03-30 19:18:42 +00:00
|
|
|
private function fetchSchedule()
|
2015-03-30 14:20:30 +00:00
|
|
|
{
|
|
|
|
$opts = array(
|
|
|
|
'http' => array(
|
|
|
|
'timeout' => 2,
|
2015-12-25 20:32:53 +00:00
|
|
|
'user_agent' => 'C3VOC Universal Streaming-Website Backend @ '.$_SERVER['HTTP_HOST'],
|
2015-03-30 14:20:30 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$context = stream_context_create($opts);
|
2015-03-30 19:18:42 +00:00
|
|
|
$schedule = file_get_contents($this->getScheduleUrl(), false, $context);
|
2015-03-30 14:20:30 +00:00
|
|
|
|
|
|
|
if(!$schedule)
|
2015-03-30 19:18:42 +00:00
|
|
|
throw new ScheduleException("Error Downloading Schedule from ".$this->getScheduleUrl());
|
|
|
|
|
|
|
|
return simplexml_load_string($schedule);
|
|
|
|
}
|
2015-03-30 14:20:30 +00:00
|
|
|
|
2015-03-30 19:18:42 +00:00
|
|
|
public function getSchedule()
|
|
|
|
{
|
|
|
|
// download schedule-xml
|
2015-04-03 08:29:50 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
$schedule = $this->fetchSchedule();
|
|
|
|
}
|
|
|
|
catch(Exception $e)
|
|
|
|
{
|
|
|
|
return array();
|
|
|
|
}
|
2015-03-30 19:18:42 +00:00
|
|
|
|
|
|
|
$mapping = $this->getScheduleToRoomSlugMapping();
|
|
|
|
$program = array();
|
2015-03-30 14:20:30 +00:00
|
|
|
|
|
|
|
// re-calculate day-ends
|
|
|
|
// some schedules have long gaps before the first talk or talks that expand beyond the dayend
|
|
|
|
// (fiffkon, i look at you)
|
|
|
|
// so to be on the safer side we calculate our own daystart/end here
|
|
|
|
foreach($schedule->day as $day)
|
|
|
|
{
|
|
|
|
$daystart = PHP_INT_MAX;
|
|
|
|
$dayend = 0;
|
|
|
|
|
|
|
|
foreach($day->room as $room)
|
|
|
|
{
|
2015-04-01 19:03:21 +00:00
|
|
|
$name = (string)$room['name'];
|
|
|
|
if($this->isRoomFiltered($name))
|
|
|
|
continue;
|
|
|
|
|
2015-03-30 14:20:30 +00:00
|
|
|
foreach($room->event as $event)
|
|
|
|
{
|
|
|
|
$start = strtotime((string)$event->date);
|
2015-03-30 19:18:42 +00:00
|
|
|
$duration = $this->strToDuration((string)$event->duration);
|
2015-03-30 14:20:30 +00:00
|
|
|
$end = $start + $duration;
|
|
|
|
|
|
|
|
$daystart = min($daystart, $start);
|
|
|
|
$dayend = max($dayend, $end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$day['start'] = $daystart;
|
|
|
|
$day['end'] = $dayend;
|
|
|
|
}
|
|
|
|
|
2016-08-06 10:46:47 +00:00
|
|
|
|
|
|
|
$daysSorted = [];
|
2015-03-30 14:20:30 +00:00
|
|
|
foreach($schedule->day as $day)
|
2016-08-06 10:46:47 +00:00
|
|
|
{
|
|
|
|
$daysSorted[] = $day;
|
|
|
|
}
|
|
|
|
|
|
|
|
usort($daysSorted, function($a, $b) {
|
|
|
|
return (int)$a['start'] - (int)$b['start'];
|
|
|
|
});
|
|
|
|
|
|
|
|
$dayidx = 0;
|
|
|
|
foreach($daysSorted as $day)
|
2015-03-30 14:20:30 +00:00
|
|
|
{
|
|
|
|
$dayidx++;
|
|
|
|
$daystart = (int)$day['start'];
|
|
|
|
$dayend = (int)$day['end'];
|
|
|
|
|
|
|
|
$roomidx = 0;
|
|
|
|
foreach($day->room as $room)
|
|
|
|
{
|
|
|
|
$roomidx++;
|
|
|
|
$lastend = false;
|
2015-03-30 19:18:42 +00:00
|
|
|
|
2016-08-19 09:33:30 +00:00
|
|
|
$name = trim((string)$room['name']);
|
2015-04-01 19:03:21 +00:00
|
|
|
if($this->isRoomFiltered($name))
|
|
|
|
continue;
|
|
|
|
|
2015-10-05 15:28:37 +00:00
|
|
|
$room_known = isset($mapping[$name]);
|
|
|
|
|
|
|
|
if($room_known)
|
2015-03-30 19:18:42 +00:00
|
|
|
$name = $mapping[$name];
|
2015-03-30 14:20:30 +00:00
|
|
|
|
2016-08-02 20:12:09 +00:00
|
|
|
$eventsSorted = [];
|
2015-03-30 14:20:30 +00:00
|
|
|
foreach($room->event as $event)
|
2016-08-02 20:12:09 +00:00
|
|
|
{
|
|
|
|
$eventsSorted[] = $event;
|
|
|
|
}
|
|
|
|
|
|
|
|
usort($eventsSorted, function($a, $b) {
|
|
|
|
$a_start = (string)$a->date;
|
|
|
|
$b_start = (string)$b->date;
|
|
|
|
|
|
|
|
return strcmp($a_start, $b_start);
|
|
|
|
});
|
|
|
|
|
|
|
|
foreach($eventsSorted as $event)
|
2015-03-30 14:20:30 +00:00
|
|
|
{
|
|
|
|
$start = strtotime((string)$event->date);
|
2015-03-30 19:18:42 +00:00
|
|
|
$duration = $this->strToDuration((string)$event->duration);
|
2015-03-30 14:20:30 +00:00
|
|
|
$end = $start + $duration;
|
|
|
|
|
|
|
|
if($lastend && $lastend < $start)
|
|
|
|
{
|
|
|
|
// synthesize pause event
|
|
|
|
$pauseduration = $start - $lastend;
|
|
|
|
$program[$name][] = array(
|
|
|
|
'special' => 'pause',
|
|
|
|
'title' => round($pauseduration / 60).' minutes pause',
|
|
|
|
|
|
|
|
'fstart' => date('c', $lastend),
|
|
|
|
'fend' => date('c', $start),
|
|
|
|
|
|
|
|
'start' => $lastend,
|
|
|
|
'end' => $start,
|
|
|
|
'duration' => $pauseduration,
|
2015-10-05 15:28:37 +00:00
|
|
|
'room_known' => $room_known,
|
2015-03-30 14:20:30 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else if(!$lastend && $daystart < $start)
|
|
|
|
{
|
|
|
|
$program[$name][] = array(
|
|
|
|
'special' => 'gap',
|
|
|
|
|
|
|
|
'fstart' => date('c', $daystart),
|
|
|
|
'fend' => date('c', $start),
|
|
|
|
|
|
|
|
'start' => $daystart,
|
|
|
|
'end' => $start,
|
|
|
|
'duration' => $start - $daystart,
|
2015-10-05 15:28:37 +00:00
|
|
|
'room_known' => $room_known,
|
2015-03-30 14:20:30 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$personnames = array();
|
2016-08-06 10:47:03 +00:00
|
|
|
if(isset($event->persons)) foreach($event->persons->person as $person)
|
2015-03-30 14:20:30 +00:00
|
|
|
$personnames[] = (string)$person;
|
|
|
|
|
|
|
|
$program[$name][] = array(
|
|
|
|
'title' => (string)$event->title,
|
|
|
|
'speaker' => implode(', ', $personnames),
|
|
|
|
|
|
|
|
'fstart' => date('c', $start),
|
|
|
|
'fend' => date('c', $end),
|
|
|
|
|
|
|
|
'start' => $start,
|
|
|
|
'end' => $end,
|
|
|
|
'duration' => $duration,
|
2015-10-05 15:28:37 +00:00
|
|
|
'room_known' => $room_known,
|
2015-03-30 14:20:30 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$lastend = $end;
|
|
|
|
}
|
|
|
|
|
|
|
|
// synthesize daychange event
|
|
|
|
if(!$lastend) $lastend = $daystart;
|
|
|
|
if($lastend < $dayend)
|
|
|
|
{
|
|
|
|
$program[$name][] = array(
|
|
|
|
'special' => 'gap',
|
|
|
|
|
|
|
|
'fstart' => date('c', $lastend),
|
|
|
|
'fend' => date('c', $dayend),
|
|
|
|
|
|
|
|
'start' => $lastend,
|
|
|
|
'end' => $dayend,
|
|
|
|
'duration' => $dayend - $lastend,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($dayidx < count($schedule->day))
|
|
|
|
{
|
|
|
|
$program[$name][] = array(
|
|
|
|
'special' => 'daychange',
|
|
|
|
'title' => 'Daychange from Day '.$dayidx.' to '.($dayidx+1),
|
|
|
|
|
|
|
|
'start' => $dayend,
|
|
|
|
'end' => (int)$schedule->day[$dayidx]['start'],
|
|
|
|
'duration' => 60*60,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-02 20:23:00 +00:00
|
|
|
|
|
|
|
if($this->has('SCHEDULE.ROOMFILTER'))
|
|
|
|
{
|
|
|
|
// sort by roomfilter
|
|
|
|
$roomfilter = $this->get('SCHEDULE.ROOMFILTER');
|
|
|
|
|
|
|
|
// map roomfilter-rooms to room-slugs
|
|
|
|
$roomfilter = array_map(function($e) use ($mapping) {
|
|
|
|
if(isset($mapping[$e]))
|
|
|
|
return $mapping[$e];
|
|
|
|
|
|
|
|
return $e;
|
|
|
|
}, $roomfilter);
|
|
|
|
|
|
|
|
// sort according to roomtilter ordering
|
|
|
|
uksort($program, function($a, $b) use ($roomfilter) {
|
|
|
|
return array_search($a, $roomfilter) - array_search($b, $roomfilter);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// sort by key
|
|
|
|
ksort($program);
|
|
|
|
}
|
|
|
|
|
2015-09-02 15:03:16 +00:00
|
|
|
return $program;
|
2015-03-30 19:18:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getDurationSum()
|
|
|
|
{
|
|
|
|
$sum = 0;
|
2015-03-31 15:06:04 +00:00
|
|
|
$schedule = $this->getSchedule();
|
|
|
|
foreach(reset($schedule) as $event)
|
2015-03-30 19:18:42 +00:00
|
|
|
$sum += $event['duration'];
|
|
|
|
|
|
|
|
return $sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function strToDuration($str)
|
|
|
|
{
|
|
|
|
$parts = explode(':', $str);
|
|
|
|
return ((int)$parts[0] * 60 + (int)$parts[1]) * 60;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getScheduleUrl()
|
|
|
|
{
|
2015-04-01 19:04:00 +00:00
|
|
|
return $this->get('SCHEDULE.URL');
|
2015-03-30 19:18:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-04 11:31:01 +00:00
|
|
|
public function getScheduleToRoomSlugMapping()
|
2015-03-30 19:18:42 +00:00
|
|
|
{
|
|
|
|
$mapping = array();
|
|
|
|
foreach($this->get('ROOMS') as $slug => $room)
|
2015-03-30 14:20:30 +00:00
|
|
|
{
|
2015-03-30 19:18:42 +00:00
|
|
|
if(isset($room['SCHEDULE_NAME']))
|
|
|
|
$mapping[ $room['SCHEDULE_NAME'] ] = $slug;
|
2015-03-30 14:20:30 +00:00
|
|
|
}
|
|
|
|
|
2015-03-30 19:18:42 +00:00
|
|
|
return $mapping;
|
2015-03-30 14:20:30 +00:00
|
|
|
}
|
2015-03-15 18:13:25 +00:00
|
|
|
}
|