diff options
author | MaZderMind | 2015-03-15 19:13:25 +0100 |
---|---|---|
committer | MaZderMind | 2015-03-29 21:42:01 +0200 |
commit | ea4b6c7699a7fbb7be3d9e5ce86c84a36b63f569 (patch) | |
tree | c919029a8b12e43c363b898a1ff9f7adf5c3312b | |
parent | 97fe6bf0af2989abbaaba138df3c54c4e55af3c9 (diff) |
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
Diffstat (limited to '')
-rw-r--r-- | config.php | 42 | ||||
-rw-r--r-- | index.php | 8 | ||||
-rw-r--r-- | model/Conference.php | 70 | ||||
-rw-r--r-- | model/Feedback.php | 11 | ||||
-rw-r--r-- | model/ModelBase.php | 42 | ||||
-rw-r--r-- | model/Overview.php | 31 | ||||
-rw-r--r-- | model/Room.php | 10 | ||||
-rw-r--r-- | model/Schedule.php | 8 | ||||
-rw-r--r-- | model/StreamList.php | 28 | ||||
-rw-r--r-- | template/assemblies/banner.phtml | 9 | ||||
-rw-r--r-- | template/assemblies/footer.phtml | 4 | ||||
-rw-r--r-- | template/assemblies/header.phtml | 12 | ||||
-rw-r--r-- | template/overview.phtml | 12 | ||||
-rw-r--r-- | template/page.phtml | 16 |
14 files changed, 221 insertions, 82 deletions
@@ -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', ); @@ -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 @@ +<?php + +class Conference extends ModelBase +{ + public function getTitle() { + return $this->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 @@ +<?php + +class Feedback extends ModelBase +{ + public function isEnabled() { + return $this->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 @@ +<?php + +class Modelbase +{ + protected function has($keychain) + { + return $this->_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 @@ <?php -require_once('model/Room.php'); - -class Overview +class Overview extends ModelBase { public function getGroups() { $groups = array(); - foreach(get('OVERVIEW.GROUPS') as $group => $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 @@ <?php -class Room +class Room extends ModelBase { private $slug; public function __construct($slug) { - if(! has('ROOMS.'.$slug)) + if(! $this->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 @@ +<?php + +class Schedule extends ModelBase +{ + public function getSimulationOffset() { + return $this->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 @@ <?php -class StreamList implements AggregateIterator +class StreamList extends ModelBase implements IteratorAggregate { private $streams = array(); + public function __construct($slug) + { + if(! $this->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')) ?> -<div class="banner"> - <?=get('CONFERENCE.BANNER_HTML')?> -</div> +<? if($conference->hasBannerHtml()): ?> + <div class="banner"> + <?=$conference->getBannerHtml()?> + </div> +<? 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 @@ <footer> - <? if(has('CONFERENCE.FOOTER_HTML')): ?> - <?= get('CONFERENCE.FOOTER_HTML') ?> + <? if($conference->hasFooterHtml()): ?> + <?= $conference->getFooterHtml() ?> <? else: ?> by <a href="https://c3voc.de">c3voc</a> <? endif ?> diff --git a/template/assemblies/header.phtml b/template/assemblies/header.phtml index 50eb9cb..cb6b991 100644 --- a/template/assemblies/header.phtml +++ b/template/assemblies/header.phtml @@ -3,22 +3,22 @@ <div class="navbar-header"> <a class="navbar-brand" href=""> <i class="icon"></i> - <?=h(get('CONFERENCE.TITLE', 'C3Voc Streaming'))?> + <?=h($conference->getTitle())?> </a> </div> <div class="nav navbar-form navbar-right button-wrapper"> - <? if(has('FEEDBACK')): ?> - <a class="form-control btn btn-default" href="feedback/"> + <? if($feedback->isEnabled()): ?> + <a class="form-control btn btn-default" href="<?=h($feedback->getUrl())?>"> <span class="fa fa-bullhorn"></span> </a> <? endif ?> - <? if(has('OVERVIEW.RELEASES')): ?> - <a class="form-control btn btn-default" href="<?=h(get('OVERVIEW.RELEASES'))?>"> + <? if($conference->hasReleases()): ?> + <a class="form-control btn btn-default" href="<?=h($conference->getReleasesUrl())?>"> <span class="fa fa-video-camera"></span> </a> <? endif ?> - <a class="form-control btn btn-default" href="about/"> + <a class="form-control btn btn-default" href="<?=h($conference->getAboutUrl())?>"> <span class="fa fa-info"></span> </a> </div> diff --git a/template/overview.phtml b/template/overview.phtml index f0eb2d2..8e26423 100644 --- a/template/overview.phtml +++ b/template/overview.phtml @@ -89,9 +89,9 @@ </div> <? endforeach ?> - <? if($overview->hasReleases() || $overview->hasRelive()): ?> + <? if($conference->hasReleases() || $conference->hasRelive()): ?> <? - $class = ($overview->hasReleases() && $overview->hasRelive()) ? + $class = ($conference->hasReleases() && $conference->hasRelive()) ? // both enabled 'col-sm-6 col-xs-12' : @@ -104,11 +104,11 @@ <h2>Recordings</h2> </div> - <? if($overview->hasReleases()): ?> + <? if($conference->hasReleases()): ?> <div class="<?=h($class)?>"> <div class="panel panel-primary"> <div class="panel-body"> - <a href="<?=h($overview->getReleasesUrl())?>"> + <a href="<?=h($conference->getReleasesUrl())?>"> <span class="fa fa-video-camera"></span> Releases </a> </div> @@ -116,11 +116,11 @@ </div> <? endif ?> - <? if($overview->hasRelive()): ?> + <? if($conference->hasRelive()): ?> <div class="<?=h($class)?>"> <div class="panel panel-primary"> <div class="panel-body"> - <a href="<?=h($overview->getReliveUrl())?>"> + <a href="<?=h($conference->getReliveUrl())?>"> <span class="fa fa-play-circle"></span> ReLive </a> </div> diff --git a/template/page.phtml b/template/page.phtml index 9af5d7b..58f502c 100644 --- a/template/page.phtml +++ b/template/page.phtml @@ -8,20 +8,20 @@ <? include("$assemblies/motd.phtml") ?> - <title><?=h($title)?> – <?=h(get('CONFERENCE.TITLE', 'C3Voc'))?> Streaming</title> + <title><?=h($title)?> – <?=h($conference->getTitle())?> Streaming</title> <meta name="robots" content="index,follow" /> - <? if(has('CONFERENCE.AUTHOR')): ?> - <meta name="author" content="<?=h(get('CONFERENCE.AUTHOR'))?>" /> + <? if($conference->hasAuthor()): ?> + <meta name="author" content="<?=h($conference->getAuthor())?>" /> <? endif ?> - <? if(has('CONFERENCE.DESCRIPTION')): ?> - <meta name="description" content="<?=h(get('CONFERENCE.DESCRIPTION'))?>" /> + <? if($conference->hasDescription()): ?> + <meta name="description" content="<?=h($conference->getDescription())?>" /> <? endif ?> - <? if(has('CONFERENCE.KEYWORDS')): ?> - <meta name="keywords" content="<?=h(get('CONFERENCE.KEYWORDS'))?>" /> + <? if($conference->hasKeywords()): ?> + <meta name="keywords" content="<?=h($conference->getKeywords())?>" /> <? endif ?> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> @@ -57,7 +57,7 @@ <? include("$assemblies/footer.phtml") ?> <span class="js-settings" - data-scheduleoffset="<?=h(get('SCHEDULE.SIMULATE_OFFSET', 0))?>" + data-scheduleoffset="<?=h($schedule->getSimulationOffset())?>" ></span> </body> </html> |