From 48a0fa9c5fe1120aeed715c42b50caaaf14c27d6 Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Mon, 24 Oct 2016 00:16:00 +0300 Subject: [PATCH] Remove unused variables, add filter by event type, rewrite CSS class generation --- schedule/index.php | 2 +- schedule/parse.php | 63 ++++++++++++++++++++++++++++++---------------- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/schedule/index.php b/schedule/index.php index 06c8171..b6e78da 100644 --- a/schedule/index.php +++ b/schedule/index.php @@ -9,7 +9,7 @@ require $requirePath . 'load.php'; require $requirePath . 'parse.php'; $sched_config = getSchedConfig(date('Y')); $data = loadData($sched_config); -//$sched_config['filterEventType'] = 'workshop'; +$sched_config['filterEventType'] = array_key_exists('event_type', $_GET) ? $_GET['event_type'] : null; $content = parseData($sched_config, $data); ?> diff --git a/schedule/parse.php b/schedule/parse.php index 16b3571..3bca53c 100644 --- a/schedule/parse.php +++ b/schedule/parse.php @@ -1,12 +1,5 @@ array( 'name' => 'English', @@ -78,7 +71,12 @@ function parseData($config, $data) { // Fill in the event ID for each time slot in each hall $events = []; - + $filtered_type_id = + array_key_exists('filterEventType', $config) && + array_key_exists($config['filterEventType'], $config['eventTypes']) ? + $config['eventTypes'][$config['filterEventType']] : + null; + foreach ($data['halls'] as $hall_id => $hall) { $hall_data = []; @@ -92,6 +90,12 @@ function parseData($config, $data) { $slot['ends_at'] >= $timestamps[1] && array_key_exists($slot['event_id'], $data['events']) ) { + if (!is_null($filtered_type_id)) { + if ($data['events'][$slot['event_id']]['event_type_id'] !== $filtered_type_id) { + continue; + } + } + $found = true; $hall_data[] = [ 'event_id' => $slot['event_id'], @@ -196,6 +200,7 @@ function parseData($config, $data) { $schedule .= ''; $lastTs = 0; + $fulltalks = ''; foreach ($events as $slot_index => $events_data) { $columns = []; @@ -225,32 +230,27 @@ function parseData($config, $data) { $speakers = ''; if (count($event['participant_user_ids']) > 0) { - $spk = array(); - $speaker_name = array(); + $spk = []; + foreach ($event['participant_user_ids'] as $uid) { if (in_array($uid, $config['hidden_speakers']) || empty($data['speakers'][$uid])) { continue; } $name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name']; - $spk[$uid] = '' . $name . ''; + $spk[] = '' . $name . ''; } + $speakers = implode (', ', $spk); } - if (in_array($event['track_id'], $config['hidden_language_tracks'])) { - $csslang = ''; - } else { - $csslang = 'schedule-' . $event['language']; - } - - $cssclass = &$data['tracks'][$event['track_id']]['css_class']; - $style = ' class="' . $cssclass . ' ' . $csslang . '"'; $content = '' . htmlspecialchars($title) . '
' . $speakers; - /* these are done by $eid, as otherwise we get some talks more than once (for example the lunch) */ + // these are done by $eid, as otherwise we get some talks more than once (for example the lunch) + // TODO: fix this, it's broken $fulltalks .= '
'; - /* We don't want '()' when we don't have a speaker name */ + + // We don't want '()' when we don't have a speaker name $fulltalk_spkr = strlen($speakers) > 0 ? (' (' . $speakers . ')') : ''; $fulltalks .= '

' . $event['title'] . ' ' . $fulltalk_spkr . '

'; $fulltalks .= '

' . $event['abstract'] . '

'; @@ -265,8 +265,27 @@ function parseData($config, $data) { } $rowspan = array_key_exists('rowspan', $event_info) ? (' rowspan="' . $event_info['rowspan'] . '"') : ''; - $columns[] = ' 1 ? ' colspan="' . $colspan . '"' : $rowspan) . '>' . $content . ''; + + // CSS + $cssClasses = []; + + if (!in_array($event['track_id'], $config['hidden_language_tracks'])) { + $cssClasses[] = 'schedule-' . $event['language']; + } + + $cssClass = $data['tracks'][$event['track_id']]['css_class']; + + if (strlen($cssClass) > 0) { + $cssClasses[] = $cssClass; + } + + $cssClasses = count($cssClasses) > 0 ? (' class="' . implode(' ', $cssClasses) . '"') : ''; + + // Render cell + $columns[] = ' 1 ? ' colspan="' . $colspan . '"' : $rowspan) . $cssClasses . '>' . $content . ''; + $lastEventId = $eid; + unset($eid, $event); } $schedule .= '';