diff --git a/schedule/class.SmartCurl.php b/schedule/class.SmartCurl.php index 6ebda1c..278446a 100644 --- a/schedule/class.SmartCurl.php +++ b/schedule/class.SmartCurl.php @@ -12,7 +12,7 @@ class SmartCurl { } if (!file_exists($this->cache_dir)) { - mkdir($this->cache_dir); + mkdir($this->cache_dir, 0777, true); } $this->cache_index = $this->cache_dir . '.json'; diff --git a/schedule/index.php b/schedule/index.php index a8739d9..e0116a1 100644 --- a/schedule/index.php +++ b/schedule/index.php @@ -7,8 +7,9 @@ require $requirePath . 'class.SmartCurl.php'; require $requirePath . 'config.php'; require $requirePath . 'load.php'; require $requirePath . 'parse.php'; -$sched_config = getSchedConfig(); +$sched_config = getSchedConfig(date('Y')); $data = loadData($sched_config); +//$sched_config['filterEventType'] = 'workshop'; $content = parseData($sched_config, $data); ?> diff --git a/schedule/parse.php b/schedule/parse.php index 6ded92b..87d6f40 100644 --- a/schedule/parse.php +++ b/schedule/parse.php @@ -17,6 +17,152 @@ function parseData($config, $data) { 'locale' => 'bg_BG.UTF8' ) ); + + // PATCH WHILE CLARION RETURNS WRONG DATA + $data['slots'][188]['ends_at'] = strtotime('2016-11-06T13:15:00.000+02:00'); + + $moments = []; + + $data['slots'] = array_map(function($slot) { + $slot['start'] = date('d.m H:i', $slot['starts_at']); + $slot['end'] = date('d.m H:i', $slot['ends_at']); + return $slot; + }, $data['slots']); + + $events = []; + + foreach ($data['halls'] as $hall_id => $hall) { + $events[$hall_id] = []; + + foreach ($data['slots'] as $slot_id => $slot) { + if ($slot['hall_id'] !== $hall_id) { + continue; + } + + if (!in_array($slot['starts_at'], $moments)) { + $moments[] = $slot['starts_at']; + } + + if (!in_array($slot['ends_at'], $moments)) { + $moments[] = $slot['ends_at']; + } + + $events[$hall_id][$slot['starts_at']] = $slot; + } + + ksort($events[$hall_id]); + } + + sort($moments); + + $times = []; + + foreach ($moments as $moment) { + $times[$moment] = date('d.m H:i', $moment); + } + + $intervals = []; + $lastTs = 0; + $last = ''; + $first = true; + + foreach ($times as $ts => $time) { + if ($first) { + $last = $time; + $lastTs = $ts; + $first = false; + continue; + } + + if (date('d.m.Y', $lastTs) !== date('d.m.Y', $ts)) { + //echo PHP_EOL; + + $last = $time; + $lastTs = $ts; + continue; + } + + //echo count($intervals), '. ', $last, ' - ', $time, PHP_EOL; + $intervals[] = [$lastTs, $ts]; + + $lastTs = $ts; + $last = $time; + } + + $schedule = []; + $hall_ids = array_keys($data['halls']); + + foreach ($data['halls'] as $hall_id => $hall) { + $hall_data = []; + + foreach ($intervals as $timestamps) { + $found = false; + + foreach ($data['slots'] as $slot_id => $slot) { + if ( + $slot['hall_id'] === $hall_id && + $slot['starts_at'] <= $timestamps[0] && + $slot['ends_at'] >= $timestamps[1] + ) { + $found = true; + $hall_data[] = [ + 'event_id' => $slot['event_id'], + 'edge' => $slot['starts_at'] === $timestamps[0] || $slot['ends_at'] === $timestamps[1], + ]; + break; + } + } + + if (!$found) { + $hall_data[] = null; + } + } + + $schedule[] = $hall_data; + } + + $schedule = array_map(null, ...$schedule); + $table = '
'; + + foreach ($hall_ids as $hall_id) { + $table .= ' | ' . $data['halls'][$hall_id]['bg'] . ' | '; + } + + $table .= ''; + continue; + } + + if ($event['edge']) { + $hasEvents = true; + } + + $columns[] = ' | ' . $data['events'][$event['event_id']]['title'] . ' (' . $event['event_id'] . ') | '; + } + + if (!$hasEvents) { + continue; + } + + $table .= '
---|---|
'; + $table .= date('H:i', $intervals[$slot_index][0]) . ' - ' . date('H:i', $intervals[$slot_index][1]); + $table .= ' | '; + $table .= implode('', $columns); + $table .= '