From 46d9f93ac3dc8a0e68a54dd63cfdc4b6b95d199e Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Mon, 24 Oct 2016 00:34:15 +0300 Subject: [PATCH] Fix filtering by event type --- schedule/parse.php | 57 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/schedule/parse.php b/schedule/parse.php index 3bca53c..4c38906 100644 --- a/schedule/parse.php +++ b/schedule/parse.php @@ -99,6 +99,7 @@ function parseData($config, $data) { $found = true; $hall_data[] = [ 'event_id' => $slot['event_id'], + 'hall_id' => $slot['hall_id'], 'edge' => $slot['starts_at'] === $timestamps[0] || $slot['ends_at'] === $timestamps[1], ]; break; @@ -112,6 +113,21 @@ function parseData($config, $data) { $events[] = $hall_data; } + + // Remove halls with no events after filtering + $count = count($events); + for ($i = 0; $i < $count; ++$i) { + $hasEvents = false; + foreach ($events[$i] as $event_info) { + if (!is_null($event_info)) { + $hasEvents = true; + break; + } + } + if (!$hasEvents) { + unset($events[$i]); + } + } // Transpose the matrix // rows->halls, cols->timeslots ===> rows->timeslots, cols->halls @@ -192,28 +208,23 @@ function parseData($config, $data) { unset($events_data); // Build the HTML - $schedule = ''; - - foreach ($data['halls'] as $hall_id => $hall) { - $schedule .= ''; - } - - $schedule .= ''; + $schedule_body = ''; $lastTs = 0; $fulltalks = ''; + $hall_ids = []; foreach ($events as $slot_index => $events_data) { $columns = []; if (date('d.m', $microslots[$slot_index][0]) !== date('d.m', $lastTs)) { - $schedule .= ''; + $schedule_body .= ''; } $lastTs = $microslots[$slot_index][0]; $lastEventId = 0; $colspan = 1; - foreach ($events_data as $hall_index => $event_info) { + foreach ($events_data as $event_info) { if ($event_info === false) { continue; } @@ -222,7 +233,11 @@ function parseData($config, $data) { $columns[] = ''; continue; } - + + if (!in_array($event_info['hall_id'], $hall_ids)) { + $hall_ids[] = $event_info['hall_id']; + } + $eid = &$event_info['event_id']; $event = &$data['events'][$eid]; @@ -288,13 +303,25 @@ function parseData($config, $data) { unset($eid, $event); } - $schedule .= ''; - $schedule .= implode('', $columns); - $schedule .= ''; + $schedule_body .= ''; + $schedule_body .= implode('', $columns); + $schedule_body .= ''; } + $schedule = '
' . $hall['bg'] . '
' . strftime('%d %B - %A', $microslots[$slot_index][0]) . '
' . strftime('%d %B - %A', $microslots[$slot_index][0]) . '
 
'; - $schedule .= strftime('%H:%M', $microslots[$slot_index][0]) . ' - ' . strftime('%H:%M', $microslots[$slot_index][1]); - $schedule .= '
'; + $schedule_body .= strftime('%H:%M', $microslots[$slot_index][0]) . ' - ' . strftime('%H:%M', $microslots[$slot_index][1]); + $schedule_body .= '
'; + + foreach ($data['halls'] as $hall_id => $hall) { + if (!in_array($hall_id, $hall_ids)) { + continue; + } + + $schedule .= ''; + } + + $schedule .= ''; + $schedule .= $schedule_body; $schedule .= '
' . $hall['bg'] . '
'; // Create the legend