diff --git a/schedule/parse.php b/schedule/parse.php index fa7956f..317b916 100644 --- a/schedule/parse.php +++ b/schedule/parse.php @@ -13,8 +13,8 @@ function parseData($config, $data) { 'locale' => 'bg_BG.UTF8' ) ); - - if ($data === false) return false; + + if ($data === false) return false; // We need to set these so we actually parse properly the dates. WP fucks up both. date_default_timezone_set('Europe/Sofia'); @@ -24,7 +24,7 @@ function parseData($config, $data) { $data['slots'] = array_filter($data['slots'], function($slot) { return isset($slot['starts_at'], $slot['ends_at'], $slot['hall_id'], $slot['event_id']); }); - + // Collect the slots for each hall, sort them in order of starting $slots = []; $timestamps = []; @@ -37,7 +37,7 @@ function parseData($config, $data) { foreach ($data['halls'] as $hall_id => $hall) { $slots[$hall_id] = []; - + foreach ($data['slots'] as $slot_id => $slot) { if ($slot['hall_id'] !== $hall_id) { continue; @@ -48,11 +48,11 @@ function parseData($config, $data) { if ($etype !== $filtered_type_id && !is_null($filtered_type_id)) { continue; } - + if (!in_array($slot['starts_at'], $timestamps)) { $timestamps[] = $slot['starts_at']; } - + if (!in_array($slot['ends_at'], $timestamps)) { $timestamps[] = $slot['ends_at']; } @@ -62,26 +62,26 @@ function parseData($config, $data) { ksort($slots[$hall_id]); if (empty($slots[$hall_id])) unset($slots[$hall_id]); } - + sort($timestamps); - + // Find all microslots (the smallest time unit) $microslots = []; $lastTs = 0; $first = true; - + foreach ($timestamps as $ts) { if ($first) { $lastTs = $ts; $first = false; continue; } - + if (date('d.m', $lastTs) !== date('d.m', $ts)) { $lastTs = $ts; continue; } - + $microslots[] = [$lastTs, $ts]; $lastTs = $ts; } @@ -90,10 +90,10 @@ function parseData($config, $data) { foreach ($data['halls'] as $hall_id => $hall) { $hall_data = []; - + foreach ($microslots as $timestamps) { $found = false; - + foreach ($data['slots'] as $slot_id => $slot) { if ( $slot['hall_id'] === $hall_id && @@ -106,7 +106,7 @@ function parseData($config, $data) { continue; } } - + $found = true; $hall_data[] = [ 'event_id' => $slot['event_id'], @@ -116,12 +116,12 @@ function parseData($config, $data) { break; } } - + if (!$found) { $hall_data[] = null; } } - + $events[$hall_id] = $hall_data; } // Remove halls with no events after filtering @@ -146,25 +146,25 @@ function parseData($config, $data) { foreach($events as $i => $val) { $hall_count = count($events[$i]); $hasEvents = false; - + for ($j = 0; $j < $hall_count; ++$j) { if (!is_null($events[$i][$j]) && $events[$i][$j]['edge']) { $hasEvents = true; continue 2; } } - + if (!$hasEvents) { unset($events[$i]); } } - + // Merge events longer than one slot $prevEventId = []; $prevEventSlot = []; $prevSlotIndex = 0; $first = true; - + foreach ($events as $slot_index => &$events_data) { if ($first) { $prevEventId = array_map(function($event_info) { @@ -175,46 +175,46 @@ function parseData($config, $data) { $first = false; continue; } - + foreach ($events_data as $hall_index => &$event_info) { if (is_null($event_info)) { $prevEventId[$hall_index] = null; $prevEventSlot[$hall_index] = null; continue; } - + if ($event_info['event_id'] !== $prevEventId[$hall_index]) { $prevEventId[$hall_index] = $event_info['event_id']; $prevEventSlot[$hall_index] = null; continue; } - + // We have a long event if (is_null($prevEventSlot[$hall_index])) { $prevEventSlot[$hall_index] = $prevSlotIndex; } - + $master_slot = &$events[$prevEventSlot[$hall_index]][$hall_index]; - + if (!array_key_exists('rowspan', $master_slot)) { $master_slot['rowspan'] = 2; } else { ++$master_slot['rowspan']; } - + unset($master_slot); - + $event_info = false; } - + unset($event_info); - + $prevSlotIndex = $slot_index; } - + unset($events_data); - + // Build the HTML $schedule_body = ''; $lastTs = 0; @@ -226,36 +226,36 @@ function parseData($config, $data) { foreach ($events as $slot_index => $events_data) { $columns = []; - + if (date('d.m', $microslots[$slot_index][0]) !== date('d.m', $lastTs)) { $schedule_body .= '
' . htmlentities($event['title']) . ' ' . $fulltalk_spkr . '
'; @@ -293,7 +293,7 @@ function parseData($config, $data) { $fulltalks .= ''; - + foreach ($data['halls'] as $hall_id => $hall) { if (!in_array($hall_id, $hall_ids)) { continue; } - + $schedule .= ' | ' . $hall[$config['lang']] . ' | '; } - + $schedule .= '
---|