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 --- config.php | 42 ++++++++++++------------ index.php | 8 +++++ 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 +++++++++++++++- template/assemblies/banner.phtml | 9 +++--- template/assemblies/footer.phtml | 4 +-- template/assemblies/header.phtml | 12 +++---- template/overview.phtml | 12 +++---- template/page.phtml | 16 ++++----- 14 files changed, 221 insertions(+), 82 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 diff --git a/config.php b/config.php index 981fb8e..1cf3891 100644 --- a/config.php +++ b/config.php @@ -61,6 +61,27 @@ $GLOBALS['CONFIG']['CONFERENCE'] = array( * Wird diese Zeile auskommentiert, wird kein Banner ausgegeben. */ //'BANNER_HTML' => '31C3 – a new dawn', + + /** + * Link zu den Recordings + * Wird diese Zeile auskommentiert, wird der Link nicht angezeigt + */ + 'RELEASES' => 'http://media.ccc.de/browse/congress/2014/index.html', + + /** + * Link zu einer (externen) ReLive-Übersichts-Seite + * Wird diese Zeile auskommentiert, wird der Link nicht angezeigt + */ + //'RELIVE' => 'http://vod.c3voc.de/', + + /** + * Alternativ kann ein ReLive-Json konfiguriert werden, um die interne + * ReLive-Ansicht zu aktivieren. + * + * Wird beides aktiviert, hat der externe Link Vorrang! + * Wird beides auskommentiert, wird der Link nicht angezeigt + */ + 'RELIVE_JSON' => 'http://vod.c3voc.de/index.json', ); /** @@ -90,27 +111,6 @@ $GLOBALS['CONFIG']['OVERVIEW'] = array( 'sendezentrum', ), ), - - /** - * Link zu den Recordings - * Wird diese Zeile auskommentiert, wird der Link nicht angezeigt - */ - 'RELEASES' => 'http://media.ccc.de/browse/congress/2014/index.html', - - /** - * Link zu einer (externen) ReLive-Übersichts-Seite - * Wird diese Zeile auskommentiert, wird der Link nicht angezeigt - */ - //'RELIVE' => 'http://vod.c3voc.de/', - - /** - * Alternativ kann ein ReLive-Json konfiguriert werden, um die interne - * ReLive-Ansicht zu aktivieren. - * - * Wird beides aktiviert, hat der externe Link Vorrang! - * Wird beides auskommentiert, wird der Link nicht angezeigt - */ - 'RELIVE_JSON' => 'http://vod.c3voc.de/index.json', ); diff --git a/index.php b/index.php index 80bf348..02a1f79 100644 --- a/index.php +++ b/index.php @@ -6,6 +6,10 @@ require_once('lib/PhpTemplate.php'); require_once('lib/Exceptions.php'); require_once('lib/helper.php'); +require_once('model/ModelBase.php'); +require_once('model/Conference.php'); +require_once('model/Feedback.php'); +require_once('model/Schedule.php'); require_once('model/Overview.php'); require_once('model/Room.php'); @@ -17,6 +21,10 @@ $tpl = new PhpTemplate('template/page.phtml'); $tpl->set(array( 'baseurl' => baseurl(), 'assemblies' => './template/assemblies/', + + 'conference' => new Conference(), + 'feedback' => new Feedback(), + 'schedule' => new Schedule(), )); 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); } diff --git a/template/assemblies/banner.phtml b/template/assemblies/banner.phtml index 02db100..f818b30 100644 --- a/template/assemblies/banner.phtml +++ b/template/assemblies/banner.phtml @@ -1,4 +1,5 @@ - if(has('CONFERENCE.BANNER_HTML')) ?> -
+ if($conference->hasBannerHtml()): ?> + + endif ?> diff --git a/template/assemblies/footer.phtml b/template/assemblies/footer.phtml index 2c5ab5d..619eff8 100644 --- a/template/assemblies/footer.phtml +++ b/template/assemblies/footer.phtml @@ -1,6 +1,6 @@