array( 'name' => 'English', 'locale' => 'en_US.UTF8' ), 'bg' => array( 'name' => 'Български', 'locale' => 'bg_BG.UTF8' ) ); $microslots = []; $data['slots'] = array_filter($data['slots'], function($slot) { return isset($slot['starts_at'], $slot['ends_at'], $slot['hall_id'], $slot['event_id']); }); $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'], $microslots)) { $microslots[] = $slot['starts_at']; } if (!in_array($slot['ends_at'], $microslots)) { $microslots[] = $slot['ends_at']; } $events[$hall_id][$slot['starts_at']] = $slot; } ksort($events[$hall_id]); } sort($microslots); $times = []; foreach ($microslots as $microslot) { $times[$microslot] = date('d.m H:i', $microslot); } $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 .= ''; $lastTs = 0; foreach ($schedule as $slot_index => $events) { $columns = []; $hasEvents = false; if (date('d.m', $intervals[$slot_index][0]) !== date('d.m', $lastTs)) { $table .= ''; } $lastTs = $intervals[$slot_index][0]; $lastEventId = 0; foreach ($events as $hall_index => $event) { if (is_null($event['event_id']) || !array_key_exists($event['event_id'], $data['events'])) { $columns[] = ''; continue; } if ($event['edge']) { $hasEvents = true; } if ($lastEventId === $event['event_id']) { $lastColumn = array_pop($columns); $lastColumn = preg_replace_callback('//', function($matches) { $colspan = array_key_exists(1, $matches) ? intval($matches[1]) + 1 : 2; return ''; $lastEventId = $event['event_id']; } if (!$hasEvents) { continue; } $table .= ''; $table .= implode('', $columns); $table .= ''; } $table .= '
' . $data['halls'][$hall_id]['bg'] . '
' . date('d.m', $intervals[$slot_index][0]) . '
 '; }, $lastColumn); $columns[] = $lastColumn; continue; } $columns[] = '' . $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'); setlocale(LC_TIME, $languages[$config['lang']]['locale']); foreach ($data['slots'] as $slot) { $slotTime = $slot['starts_at']; $slotDate = date('d', $slotTime); if ($slotDate !== $date) { $lines[] = ''; $lines[] = '' . strftime('%d %B - %A', $slotTime) . ''; $lines[] = ' '; $lines[] = ''; $date = $slotDate; } if ($slotTime !== $time) { if ($time !== 0) { $lines[] = ''; } $lines[] = ''; $lines[] = '' . date('H:i', $slot['starts_at']) . ' - ' . date('H:i', $slot['ends_at']) . ''; $time = $slotTime; } $eid = &$slot['event_id']; if (!array_key_exists($eid, $data['events'])) { continue; } $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'; } else { $title = mb_substr($event['title'], 0, $config['cut_len']) . (mb_strlen($event['title']) > $config['cut_len'] ? '...' : ''); $speakers = ''; if (count($event['participant_user_ids']) > 0) { $speakers = json_encode($event['participant_user_ids']) . '
'; $spk = array(); $speaker_name = array(); foreach ($event['participant_user_ids'] as $uid) { /* The check for uid==4 is for us not to show the "Opefest Team" as a presenter for lunches, etc. */ if ($uid == 4 || empty ($data['speakers'][$uid])) { continue; } else { /* TODO: fix the URL */ $name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name']; $spk[$uid] = '' . $name . ''; } } $speakers = implode (', ', $spk); } /* Hack, we don't want language for the misc track. This is the same for all years. */ if ('misc' !== $data['tracks'][$event['track_id']]['name']['en']) { $csslang = 'schedule-' . $event['language']; } else { $csslang = ''; } $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) */ $fulltalks .= '
'; /* We don't want '()' when we don't have a speaker name */ $fulltalk_spkr = strlen($speakers)>1 ? ' (' . $speakers . ')' : ''; $fulltalks .= '

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

'; $fulltalks .= '

' . $event['abstract'] . '

'; $fulltalks .= '
'; if ($slot['event_id'] === $prev_event_id) { array_pop($lines); $lines[] = '' . $content . ''; } else { $lines[] = '' . $content . ''; $colspan = 1; } } $prev_event_id = $slot['event_id']; } $lines[] = ''; /* create the legend */ $legend = ''; foreach($data['tracks'] as $track) { $legend .= '' . $track['name'][$config['lang']] . ''; } foreach ($languages as $code => $lang) { $legend .= '' . $lang['name'] . ''; } $gspk = '
'; $fspk = ''; $types = [ 'twitter' => [ 'class' => 'twitter', 'url' => 'https://twitter.com/', ], 'github' => [ 'class' => 'github', 'url' => 'https://github.com/', ], 'email' => [ 'class' => 'envelope', 'url' => 'mailto:', ], ]; foreach ($data['speakers'] as $speaker) { $name = $speaker['first_name'] . ' ' . $speaker['last_name']; $gspk .= ''; $fspk .= '
'; $fspk .= '' . $name . ''; $fspk .= '

' . $name . '

'; $fspk .= '
'; foreach ($types as $type => $param) { if (!empty($speaker[$type])) { $fspk .= ''; } } $fspk .= '
'; $fspk .= '

' . $speaker['biography'] . '

'; $fspk .= '
'; } $gspk .= '
'; return compact('lines', 'fulltalks', 'gspk', 'fspk', 'legend'); }