diff options
author | MaZderMind | 2018-05-12 11:26:14 +0200 |
---|---|---|
committer | MaZderMind | 2018-05-12 11:26:14 +0200 |
commit | 59f7c88ac3c8454eb0812dcb044e2854d9241001 (patch) | |
tree | 8688ac2112062252ed77961ed9289065c929041d | |
parent | 2cf00ac475500f007bce90cf81d8d582208650c9 (diff) | |
parent | 622b1f030c5c931704b7e997918dad2dcfd48551 (diff) |
Merge branch 'feature/talkinfo-in-json'
-rw-r--r-- | model/Room.php | 20 | ||||
-rw-r--r-- | model/Schedule.php | 9 | ||||
-rw-r--r-- | template/overview.phtml | 2 | ||||
-rw-r--r-- | view/overview.php | 19 | ||||
-rw-r--r-- | view/streams-json-v2.php | 6 |
5 files changed, 43 insertions, 13 deletions
diff --git a/model/Room.php b/model/Room.php index 7089532..3552f60 100644 --- a/model/Room.php +++ b/model/Room.php @@ -4,6 +4,7 @@ class Room { private $slug; private $conference; + private $talks; public function __construct(Conference $conference, $slug) { @@ -16,8 +17,27 @@ class Room throw new NotFoundException('Room '.$slug); $this->slug = $slug; + + $schedule = $conference->getSchedule(); + $talksPerRoom = $schedule->getSchedule(); + $scheduleName = $this->getScheduleName(); + + $this->talks = isset($talksPerRoom[$scheduleName]) ? $talksPerRoom[$scheduleName] : []; } + public function getCurrentTalk($now) + { + return array_filter_last($this->talks, function($talk) use ($now) { + return $talk['start'] < $now && $talk['end'] > $now; + }); + } + + public function getNextTalk($now) + { + return array_filter_first($this->talks, function($talk) use ($now) { + return !isset($talk['special']) && $talk['start'] > $now; + }); + } public function getConference() { return $this->conference; diff --git a/model/Schedule.php b/model/Schedule.php index ec4ddc7..4b5d25e 100644 --- a/model/Schedule.php +++ b/model/Schedule.php @@ -44,6 +44,15 @@ class Schedule return $this->getConference()->getRoomIfExists( @$mapping[$scheduleRoom] ); } + public function getScheduleDisplayTime($basetime = null) + { + if(is_null($basetime)) { + $basetime = time(); + } + + return $basetime + $this->getSimulationOffset(); + } + private function fetchSchedule() { $schedule = @file_get_contents($this->getScheduleCache()); diff --git a/template/overview.phtml b/template/overview.phtml index 513f8e5..71414ec 100644 --- a/template/overview.phtml +++ b/template/overview.phtml @@ -65,7 +65,7 @@ <? endif ?> <? if($room->hasSchedule()): ?> - <? $upcoming = @$upcomingTalksPerRoom[ $room->getScheduleName() ] ?: [] ?> + <? $upcoming = @$upcomingTalksPerRoom[ $room->getSlug() ] ?: [] ?> <div class="program-schedule"> <div class="talk current-talk" title="<?=h(@$upcoming['current']['title'] ?: 'none') ?>"> <strong>Now (since <?=date('G:i', @$upcoming['current']['start']) ?>):</strong><br/> diff --git a/view/overview.php b/view/overview.php index adc8d5f..fb9d15d 100644 --- a/view/overview.php +++ b/view/overview.php @@ -2,19 +2,14 @@ $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; - }), +$now = $schedule->getScheduleDisplayTime(); +$upcomingTalksPerRoom = []; +foreach ($conference->getRooms() as $room) { + $upcomingTalksPerRoom[$room->getSlug()] = [ + 'current' => $room->getCurrentTalk($now), + 'next' => $room->getNextTalk($now), ]; -}, $talksPerRoom); +}; echo $tpl->render(array( 'page' => 'overview', diff --git a/view/streams-json-v2.php b/view/streams-json-v2.php index 114e73e..591e309 100644 --- a/view/streams-json-v2.php +++ b/view/streams-json-v2.php @@ -2,9 +2,11 @@ header('Content-Type: application/json'); +$basetime = time(); $struct = []; foreach (Conferences::getActiveConferences() as $conference) { + $now = $conference->getSchedule()->getScheduleDisplayTime($basetime); $overview = $conference->getOverview(); $groupstruct = array(); @@ -91,6 +93,10 @@ foreach (Conferences::getActiveConferences() as $conference) 'link' => forceslash(baseurl()).$room->getLink(), 'display' => $room->getDisplay(), 'stream' => $room->getStream(), + 'talks' => [ + 'current' => $room->getCurrentTalk($now), + 'next' => $room->getNextTalk($now), + ], 'streams' => $streams, ); } |