From 888bff1972e18a7f32d55fcc23cd4900d03c7d61 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sat, 12 May 2018 01:57:14 +0200 Subject: migrate logic to select current & upcoming talk into the Room class --- model/Room.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'model') 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; -- cgit v1.3.1 From 91a653392c0e66f1941036e2b17d8fa6b162cde0 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sat, 12 May 2018 02:00:51 +0200 Subject: migrate logic for calculating schedule display time into schedule class --- model/Schedule.php | 9 +++++++++ view/overview.php | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'model') 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/view/overview.php b/view/overview.php index e5032c4..fb9d15d 100644 --- a/view/overview.php +++ b/view/overview.php @@ -2,7 +2,7 @@ $schedule = $conference->getSchedule(); -$now = time() + $schedule->getSimulationOffset(); +$now = $schedule->getScheduleDisplayTime(); $upcomingTalksPerRoom = []; foreach ($conference->getRooms() as $room) { $upcomingTalksPerRoom[$room->getSlug()] = [ -- cgit v1.3.1