From da5810e68b1042af7f207eaaa93bc513abce88c4 Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Sat, 22 Oct 2016 03:23:29 +0300 Subject: [PATCH] [WIP] Properly format the schedule, fix minor bugs/whitespace --- schedule/class.SmartCurl.php | 2 +- schedule/index.php | 3 +- schedule/parse.php | 161 ++++++++++++++++++++++++++++++++++- 3 files changed, 161 insertions(+), 5 deletions(-) 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 .= ''; + } + + $table .= ''; + + foreach ($schedule as $slot_index => $events) { + $columns = []; + $hasEvents = false; + + foreach ($events as $hall_index => $event) { + if (is_null($event['event_id'])) { + $columns[] = ''; + continue; + } + + if ($event['edge']) { + $hasEvents = true; + } + + $columns[] = ''; + } + + if (!$hasEvents) { + continue; + } + + $table .= ''; + $table .= implode('', $columns); + $table .= ''; + } + + $table .= '
' . $data['halls'][$hall_id]['bg'] . '
 ' . $data['events'][$event['event_id']]['title'] . ' (' . $event['event_id'] . ')
'; + $table .= date('H:i', $intervals[$slot_index][0]) . ' - ' . date('H:i', $intervals[$slot_index][1]); + $table .= '
'; + + echo $table; + //var_dump($schedule); + exit; /* We need to set these so we actually parse properly the dates. WP fucks up both. */ date_default_timezone_set('Europe/Sofia'); @@ -54,6 +200,15 @@ function parseData($config, $data) { $event = &$data['events'][$eid]; + if ( + array_key_exists('filterEventType', $config) && + array_key_exists($config['filterEventType'], $config['eventTypes']) + ) { + if ($config['eventTypes'][$config['filterEventType']] !== $event['event_type_id']) { + continue; + } + } + if (is_null($eid)) { $lines[] = 'TBA'; } @@ -73,7 +228,7 @@ function parseData($config, $data) { } else { /* TODO: fix the URL */ $name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name']; - $spk[$uid] = '' . $name . ''; + $spk[$uid] = '' . $name . ''; } } $speakers = implode (', ', $spk); @@ -147,11 +302,11 @@ function parseData($config, $data) { $gspk .= '
'; $gspk .= ''; - $gspk .= '' . $name .''; + $gspk .= '' . $name . ''; $gspk .= '
'; $fspk .= '
'; - $fspk .= '' . $name .''; + $fspk .= '' . $name . ''; $fspk .= '

' . $name . '

'; $fspk .= '
';