From f6c0270d40f6730fe1e1820f2866b08792df1db6 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sat, 10 Dec 2016 18:22:34 +0100 Subject: rewrite data-model so that every configuration option is accessed through the conference --- model/Schedule.php | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'model/Schedule.php') diff --git a/model/Schedule.php b/model/Schedule.php index c0ff69b..0b789f2 100644 --- a/model/Schedule.php +++ b/model/Schedule.php @@ -1,26 +1,37 @@ conference = $conference; + } + + public function getConference() { + return $this->conference; + } + public function isEnabled() { - return $this->has('SCHEDULE'); + return $this->getConference()->has('SCHEDULE'); } private function isRoomFiltered($room) { - if(!$this->has('SCHEDULE.ROOMFILTER')) + if(!$this->getConference()->has('SCHEDULE.ROOMFILTER')) return false; - $rooms = $this->get('SCHEDULE.ROOMFILTER'); + $rooms = $this->getConference()->get('SCHEDULE.ROOMFILTER'); return !in_array($room, $rooms); } public function getSimulationOffset() { - return $this->get('SCHEDULE.SIMULATE_OFFSET', 0); + return $this->getConference()->get('SCHEDULE.SIMULATE_OFFSET', 0); } public function getScale() { - return floatval($this->get('SCHEDULE.SCALE', 7)); + return floatval($this->getConference()->get('SCHEDULE.SCALE', 7)); } private function fetchSchedule() @@ -35,7 +46,7 @@ class Schedule extends ModelBase $schedule = file_get_contents($this->getScheduleUrl(), false, $context); if(!$schedule) - throw new ScheduleException("Error Downloading Schedule from ".$this->getScheduleUrl()); + throw new ScheduleException("Error Downloading Schedule from ".$this->getConference()->getScheduleUrl()); return simplexml_load_string($schedule); } @@ -49,10 +60,10 @@ class Schedule extends ModelBase } catch(Exception $e) { - return array(); + return array('_error' => (string)$e); } - $mapping = $this->getScheduleToRoomSlugMapping(); + $mapping = $this->getConference()->getScheduleToRoomSlugMapping(); $program = array(); // re-calculate day-ends @@ -220,10 +231,10 @@ class Schedule extends ModelBase } - if($this->has('SCHEDULE.ROOMFILTER')) + if($this->getConference()->has('SCHEDULE.ROOMFILTER')) { // sort by roomfilter - $roomfilter = $this->get('SCHEDULE.ROOMFILTER'); + $roomfilter = $this->getConference()->get('SCHEDULE.ROOMFILTER'); // map roomfilter-rooms to room-slugs $roomfilter = array_map(function($e) use ($mapping) { @@ -246,7 +257,7 @@ class Schedule extends ModelBase public function getDurationSum() { $sum = 0; - $schedule = $this->getSchedule(); + $schedule = $this->getConference()->getSchedule(); foreach(reset($schedule) as $event) $sum += $event['duration']; @@ -263,13 +274,13 @@ class Schedule extends ModelBase private function getScheduleUrl() { - return $this->get('SCHEDULE.URL'); + return $this->getConference()->get('SCHEDULE.URL'); } public function getScheduleToRoomSlugMapping() { $mapping = array(); - foreach($this->get('ROOMS') as $slug => $room) + foreach($this->getConference()->get('ROOMS') as $slug => $room) { if(isset($room['SCHEDULE_NAME'])) $mapping[ $room['SCHEDULE_NAME'] ] = $slug; -- cgit v1.2.3