aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaZderMind2016-12-18 13:31:34 +0100
committerMaZderMind2016-12-18 13:31:34 +0100
commit35e7a2b2adad42b077de60d1566c22da62edeb77 (patch)
treebe89253bbf80fc8383311137761a8a472e5d8b40
parent46634852dc1af3fe53136a2d48bc3157e3bbad62 (diff)
move upcoming & current logic from javascript/ajax into php
-rw-r--r--assets/js/lustiges-script.js74
-rw-r--r--index.php5
-rw-r--r--lib/helper.php31
-rw-r--r--template/overview.phtml7
-rw-r--r--view/overview.php18
-rw-r--r--view/schedule-json.php13
6 files changed, 53 insertions, 95 deletions
diff --git a/assets/js/lustiges-script.js b/assets/js/lustiges-script.js
index 78b8758..65fc6ef 100644
--- a/assets/js/lustiges-script.js
+++ b/assets/js/lustiges-script.js
@@ -176,80 +176,6 @@ $(function() {
});
});
-// startpage schedule teaser
-$(function() {
- var
- updateTimer = 5*1000, /* update display every 5 seconds */
- refetchTimer = 10*60*1000, /* re-request current / upcoming schedule every 10 minutes */
- scheduleData = {},
- $lecture = $('.room.has-schedule');
-
- if($lecture.length == 0)
- return;
-
- function fetchProgram() {
- $.ajax({
- url: $('div[data-schedule-url]').data('schedule-url'),
- dataType: 'json',
- success: function(data) {
- scheduleData = data;
- updateProgtamTeaser();
- },
-
- // success & error
- complete: function() {
- setTimeout(fetchProgram, refetchTimer);
- }
- });
- }
-
- function updateProgtamTeaser() {
- var
- // corrected "now" timestamp in unix-counting (seconds, not microseconds)
- now = (Date.now() / 1000);
-
- $.each(scheduleData, function(room, talks) {
- var currentTalk, nextTalk;
-
- $.each(talks, function(room, talk) {
-
- if(!talk.room_known)
- return;
-
- if(talk.start < now && talk.end > now)
- currentTalk = talk;
-
- if(!nextTalk && !talk.special && talk.start > now)
- nextTalk = talk;
-
- });
-
- var s = nextTalk ? new Date(nextTalk.start*1000) : new Date();
- if(currentTalk)
- $lecture.filter('.room-'+room)
- .find('.current-talk')
- .removeClass('hidden')
- .find('.t')
- .text(currentTalk.special ? 'none' : currentTalk.title)
-
- if(nextTalk)
- $lecture.filter('.room-'+room)
- .find('.next-talk')
- .toggleClass('hidden', !nextTalk || nextTalk.special || (nextTalk.start - now > 60*60))
- .find('strong')
- .text(s.getHours()+':'+(s.getMinutes() < 10 ? '0' : '')+s.getMinutes())
- .end()
- .find('.t')
- .text(nextTalk ? nextTalk.title : '')
- .end()
- });
-
- setTimeout(updateProgtamTeaser, updateTimer);
- }
-
- fetchProgram();
-});
-
// feedback form
$(function() {
$('.feedback-form').on('submit', function(e) {
diff --git a/index.php b/index.php
index ca0a6d4..409d75e 100644
--- a/index.php
+++ b/index.php
@@ -196,11 +196,6 @@ try {
require('view/feedback-read.php');
}
- else if($route == 'schedule.json')
- {
- require('view/schedule-json.php');
- }
-
else if($route == 'gen/main.css')
{
if(Conferences::hasCustomStyles($mandator))
diff --git a/lib/helper.php b/lib/helper.php
index df7f329..1925382 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -114,3 +114,34 @@ function url_params()
return '';
}
+
+/**
+ * returns the fielst element matching $predicate or null, if none matched.
+ * $predicate is a callable that receives one array value at a time and can
+ * return a bool'ish value
+ */
+function array_filter_first($array, $predicate)
+{
+ foreach ($array as $value) {
+ if( $predicate($value) ) {
+ return $value;
+ }
+ }
+
+ return null;
+}
+/**
+ * returns the fielst element matching $predicate or null, if none matched.
+ * $predicate is a callable that receives one array value at a time and can
+ * return a bool'ish value
+ */
+function array_filter_last($array, $predicate)
+{
+ foreach (array_reverse($array) as $value) {
+ if( $predicate($value) ) {
+ return $value;
+ }
+ }
+
+ return null;
+}
diff --git a/template/overview.phtml b/template/overview.phtml
index 02f0b5f..39cca02 100644
--- a/template/overview.phtml
+++ b/template/overview.phtml
@@ -1,6 +1,6 @@
<? include("$assemblies/banner.phtml") ?>
-<div class="container" data-schedule-url="<?=h($conference->getScheduleJsonUrl())?>">
+<div class="container">
<div class="row headline">
<div class="col-xs-12">
<h1><?=h($title)?></h1>
@@ -78,15 +78,16 @@
</a>
<? if($room->hasSchedule()): ?>
+ <? $upcoming = @$upcomingTalksPerRoom[ $room->getScheduleName() ] ?: [] ?>
<div class="program-schedule">
<div class="talk current-talk">
<strong>Now:</strong>
- <span class="t">none</span>
+ <span class="t"><?=h(@$upcoming['current']['title'] ?: 'none') ?></span>
</div>
<div class="talk next-talk">
<strong>Next Talk:</strong>
- <span class="t">none</span>
+ <span class="t"><?=h(@$upcoming['next']['title'] ?: 'none') ?></span>
</div>
</div>
<? endif ?>
diff --git a/view/overview.php b/view/overview.php
index 93cf007..adc8d5f 100644
--- a/view/overview.php
+++ b/view/overview.php
@@ -1,8 +1,26 @@
<?php
+$schedule = $conference->getSchedule();
+
+$talksPerRoom = $schedule->getSchedule();
+$now = time() + $schedule->getSimulationOffset();
+
+$upcomingTalksPerRoom = array_map(function($talks) use($now) {
+ return [
+ 'current' => array_filter_last($talks, function($talk) use ($now) {
+ return $talk['start'] < $now && $talk['end'] > $now;
+ }),
+ 'next' => array_filter_first($talks, function($talk) use ($now) {
+ return !isset($talk['special']) && $talk['start'] > $now;
+ }),
+ ];
+}, $talksPerRoom);
+
echo $tpl->render(array(
'page' => 'overview',
'title' => 'Live-Streams',
'overview' => $conference->getOverview(),
+
+ 'upcomingTalksPerRoom' => $upcomingTalksPerRoom,
));
diff --git a/view/schedule-json.php b/view/schedule-json.php
deleted file mode 100644
index 19346fd..0000000
--- a/view/schedule-json.php
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-
-$schedule = $conference->getSchedule();
-if(!$schedule->isEnabled())
- throw new NotFoundException('Schedule is disabled');
-
-header('Content-Type: application/json');
-
-if($conference->isClosed())
- echo '{}';
-
-else
- echo json_encode($schedule->getSchedule(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);