aboutsummaryrefslogtreecommitdiff
path: root/lib/program.php
diff options
context:
space:
mode:
authorMaZderMind2014-11-03 21:53:30 +0100
committerMaZderMind2014-11-07 00:17:40 +0100
commitdb0a85ea97096af4529b0ea3b903d182144c1310 (patch)
tree7dc8cebc458175627c7dd809ec67d6c2288cc221 /lib/program.php
parent82a054e876424cf055793ae653fbb40b6d5e58ec (diff)
experimental program view
Diffstat (limited to 'lib/program.php')
-rw-r--r--lib/program.php107
1 files changed, 107 insertions, 0 deletions
diff --git a/lib/program.php b/lib/program.php
new file mode 100644
index 0000000..900d1d9
--- /dev/null
+++ b/lib/program.php
@@ -0,0 +1,107 @@
+<?php
+
+function program()
+{
+ $cacheidx = __FILE__.':'.__FUNCTION__.':program';
+ if(function_exists('apc_fetch') && $program = apc_fetch($cacheidx))
+ return $program;
+
+ echo 'fresh';
+ $program = array();
+ $schedule = simplexml_load_file($GLOBALS['CONFIG']['SCHEDULE']);
+
+ $dayidx = 0;
+ foreach($schedule->day as $day)
+ {
+ $dayidx++;
+ $daystart = strtotime((string)$day['start']);
+ $dayend = strtotime((string)$day['end']);
+
+ $roomidx = 0;
+ foreach($day->room as $room)
+ {
+ $roomidx++;
+ $name = (string)$room['name'];
+ $lastend = false;
+
+ foreach ($room->event as $event)
+ {
+ $start = strtotime((string)$event->date);
+ $duration = strtoduration((string)$event->duration);
+ $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,
+ );
+ }
+ 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,
+ );
+ }
+
+ $program[$name][] = array(
+ 'title' => (string)$event->title,
+
+ 'fstart' => date('c', $start),
+ 'fend' => date('c', $end),
+
+ 'start' => $start,
+ 'end' => $end,
+ 'duration' => $duration,
+ );
+
+ $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),
+ );
+ }
+ }
+ }
+
+ if(function_exists('apc_store'))
+ apc_store($cacheidx, $program, $GLOBALS['CONFIG']['SCHEDULE_CACHE_TTL']);
+
+ return $program;
+}