aboutsummaryrefslogtreecommitdiff
path: root/lib/program.php
blob: 900d1d9b50bf5b4fb0de0f4efc5ff5e7f32e6861 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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;
}