From ea4b6c7699a7fbb7be3d9e5ce86c84a36b63f569 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 15 Mar 2015 19:13:25 +0100 Subject: Move get/set-Calls into ModelBase and abstract all access into a Model Conflicts: model/Overview.php model/Room.php model/StreamList.php tests/ModelTestbase.php --- model/Conference.php | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ model/Feedback.php | 11 +++++++++ model/ModelBase.php | 42 +++++++++++++++++++++++++++++++ model/Overview.php | 31 ++--------------------- model/Room.php | 10 ++++---- model/Schedule.php | 8 ++++++ model/StreamList.php | 28 ++++++++++++++++++++- 7 files changed, 165 insertions(+), 35 deletions(-) create mode 100644 model/Conference.php create mode 100644 model/Feedback.php create mode 100644 model/ModelBase.php create mode 100644 model/Schedule.php (limited to 'model') diff --git a/model/Conference.php b/model/Conference.php new file mode 100644 index 0000000..6753c0c --- /dev/null +++ b/model/Conference.php @@ -0,0 +1,70 @@ +get('CONFERENCE.TITLE', 'C3Voc Streaming'); + } + + public function hasAuthor() { + return $this->has('CONFERENCE.AUTHOR'); + } + public function getAuthor() { + return $this->get('CONFERENCE.AUTHOR', ''); + } + + public function hasDescription() { + return $this->has('CONFERENCE.DESCRIPTION'); + } + public function getDescription() { + return $this->get('CONFERENCE.DESCRIPTION', ''); + } + + public function hasKeywords() { + return $this->has('CONFERENCE.KEYWORDS'); + } + public function getKeywords() { + return $this->get('CONFERENCE.KEYWORDS', ''); + } + + + + public function hasReleases() { + return $this->has('CONFERENCE.RELEASES'); + } + public function getReleasesUrl() { + return $this->get('CONFERENCE.RELEASES'); + } + + public function hasRelive() { + return $this->has('CONFERENCE.RELIVE') || $this->has('CONFERENCE.RELIVE_JSON'); + } + public function getReliveUrl() { + if($this->has('CONFERENCE.RELIVE')) + return $this->get('CONFERENCE.RELIVE'); + + elseif($this->has('CONFERENCE.RELIVE_JSON')) + return 'relive/'; + + else + return null; + } + + public function hasBannerHtml() { + return $this->has('CONFERENCE.BANNER_HTML'); + } + public function getBannerHtml() { + return $this->get('CONFERENCE.BANNER_HTML'); + } + + public function hasFooterHtml() { + return $this->has('CONFERENCE.FOOTER_HTML'); + } + public function getFooterHtml() { + return $this->get('CONFERENCE.FOOTER_HTML'); + } + + public function getAboutUrl() { + return 'about/'; + } +} diff --git a/model/Feedback.php b/model/Feedback.php new file mode 100644 index 0000000..86ef886 --- /dev/null +++ b/model/Feedback.php @@ -0,0 +1,11 @@ +has('FEEDBACK'); + } + public function getUrl() { + return 'feedback/'; + } +} diff --git a/model/ModelBase.php b/model/ModelBase.php new file mode 100644 index 0000000..1ee41b4 --- /dev/null +++ b/model/ModelBase.php @@ -0,0 +1,42 @@ +_has($GLOBALS['CONFIG'], $keychain); + } + private function _has($array, $keychain) + { + if(!is_array($keychain)) + $keychain = explode('.', $keychain); + + $key = $keychain[0]; + if(!isset($array[$key])) + return false; + + if(count($keychain) == 1) + return true; + + return $this->_has($array[$key], array_slice($keychain, 1)); + } + + protected function get($keychain, $default = null) + { + return $this->_get($GLOBALS['CONFIG'], $keychain, $default); + } + private function _get($array, $keychain, $default) + { + if(!is_array($keychain)) + $keychain = explode('.', $keychain); + + $key = $keychain[0]; + if(!isset($array[$key])) + return $default; + + if(count($keychain) == 1) + return $array[$key]; + + return $this->_get($array[$key], array_slice($keychain, 1), $default); + } +} diff --git a/model/Overview.php b/model/Overview.php index 10507cc..f02f9f2 100644 --- a/model/Overview.php +++ b/model/Overview.php @@ -1,13 +1,11 @@ $rooms) + foreach($this->get('OVERVIEW.GROUPS') as $group => $rooms) { foreach($rooms as $room) { @@ -24,29 +22,4 @@ class Overview return $groups; } - - public function getReleasesUrl() { - return get('OVERVIEW.RELEASES'); - } - - public function getReliveUrl() { - if(has('OVERVIEW.RELIVE')) - return get('OVERVIEW.RELIVE'); - - elseif(has('OVERVIEW.RELIVE_JSON')) - return 'relive/'; - - else - return null; - } - - - - public function hasRelive() { - return has('OVERVIEW.RELIVE') || has('OVERVIEW.RELIVE_JSON'); - } - - public function hasReleases() { - return has('OVERVIEW.RELEASES'); - } } diff --git a/model/Room.php b/model/Room.php index fc1b40d..c7e51f9 100644 --- a/model/Room.php +++ b/model/Room.php @@ -1,12 +1,12 @@ has('ROOMS.'.$slug)) throw new NotFoundException('Room '.$slug); $this->slug = $slug; @@ -26,11 +26,11 @@ class Room } public function getStream() { - return get('ROOMS.'.$this->getSlug().'.STREAM', $this->getSlug()); + return $this->get('ROOMS.'.$this->getSlug().'.STREAM', $this->getSlug()); } public function getDisplay() { - return get('ROOMS.'.$this->getSlug().'.DISPLAY', $this->getSlug()); + return $this->get('ROOMS.'.$this->getSlug().'.DISPLAY', $this->getSlug()); } @@ -40,6 +40,6 @@ class Room } public function hasSchedule() { - return get('ROOMS.'.$this->getSlug().'.SCHEDULE') && has('SCHEDULE'); + return $this->get('ROOMS.'.$this->getSlug().'.SCHEDULE') && $this->has('SCHEDULE'); } } diff --git a/model/Schedule.php b/model/Schedule.php new file mode 100644 index 0000000..db940ce --- /dev/null +++ b/model/Schedule.php @@ -0,0 +1,8 @@ +get('SCHEDULE.SIMULATE_OFFSET', 0); + } +} diff --git a/model/StreamList.php b/model/StreamList.php index 531a787..d203a52 100644 --- a/model/StreamList.php +++ b/model/StreamList.php @@ -1,9 +1,35 @@ has('ROOMS.'.$slug)) + throw new NotFoundException('Room '.$slug); + + $this->slug = $slug; + $this->streams = array(); + + $streams = $this->get("ROOMS.$slug.STREAMS"); + foreach((array)$streams as $stream) { + $this->streams[$stream] = explode('-', $stream); + } + } + + public function getRoomSlug() { + return $this->slug; + } + + public function getRoom() { + return new Room($this->getRoomSlug()); + } + + public function getStreams() { + return array_keys($this->streams); + } + public function getIterator() { return new ArrayIterator($this->streams); } -- cgit v1.2.3