diff options
author | MaZderMind | 2016-12-18 13:34:57 +0100 |
---|---|---|
committer | MaZderMind | 2016-12-18 13:34:57 +0100 |
commit | a12d86ec058bc89e6feeda6ec8cfce691269b0a9 (patch) | |
tree | 6be1f764a8addd025eb774bcd2039788a4b1873f /model/Conferences.php | |
parent | 521f0e2e1c94538fdce65a021144180f368364d9 (diff) | |
parent | efd0b59f8ed363e12211894d8892e4d18b198c04 (diff) |
Merge branch 'master' into events/33c3
Diffstat (limited to 'model/Conferences.php')
-rw-r--r-- | model/Conferences.php | 73 |
1 files changed, 34 insertions, 39 deletions
diff --git a/model/Conferences.php b/model/Conferences.php index 461186f..f930e32 100644 --- a/model/Conferences.php +++ b/model/Conferences.php @@ -1,30 +1,41 @@ <?php -class Conferences extends ModelBase +class Conferences { const MANDATOR_DIR = 'configs/conferences/'; + public static function listConferences() { + $directories = scandir(forceslash(Conferences::MANDATOR_DIR)); + $conferences = array_filter($directories, function($dirname) { + return $dirname[0] != '.'; + }); + + return $conferences; + } + public static function getConferences() { $conferences = []; - foreach(scandir(forceslash(Conferences::MANDATOR_DIR)) as $el) + foreach(Conferences::listConferences() as $conference) { - if($el[0] == '.') - continue; - - $conferences[$el] = Conferences::getConferenceInformation($el); + try { + $conferences[$conference] = Conferences::getConference($conference); + } + catch(Exception $e) { + // ignore unloadable conferences + } } return $conferences; } public static function getConferencesCount() { - return count(Conferences::getConferences()); + return count(Conferences::listConferences()); } public static function getActiveConferences() { return array_values(array_filter( - Conferences::getConferences(), - function($info) { - return $info['active']; + Conferences::getConferencesSorted(), + function($conference) { + return !$conference->isClosed(); } )); } @@ -37,7 +48,7 @@ class Conferences extends ModelBase $sorted = Conferences::getConferences(); usort($sorted, function($a, $b) { - return @$b['CONFIG']['CONFERENCE']['STARTS_AT'] - @$a['CONFIG']['CONFERENCE']['STARTS_AT']; + return $b->startsAt() > $a->endsAt() ? 1 : -1; }); return $sorted; @@ -47,7 +58,7 @@ class Conferences extends ModelBase $sorted = Conferences::getConferencesSorted(); $finished = array_values(array_filter($sorted, function($c) { - return @$c['CONFIG']['CONFERENCE']['ENDS_AT'] < time(); + return $c->hasEnded(); })); return $finished; @@ -58,33 +69,22 @@ class Conferences extends ModelBase } public static function exists($mandator) { - return array_key_exists($mandator, Conferences::getConferences()); + return in_array($mandator, Conferences::listConferences()); } - public static function getConferenceInformation($mandator) { - if(isset($GLOBALS['CONFIG'])) - $saved_config = $GLOBALS['CONFIG']; - - Conferences::load($mandator); - $conf = new Conference(); - $info = [ - 'slug' => $mandator, - 'link' => forceslash($mandator).url_params(), - 'active' => !$conf->isClosed(), - 'title' => $conf->getTitle(), - 'description' => $conf->getDescription(), + public static function loadConferenceConfig($mandator) { + $configfile = forceslash(Conferences::MANDATOR_DIR).forceslash($mandator).'config.php'; + $config = include($configfile); - 'relive' => $conf->hasRelive() ? forceslash($mandator).$conf->getReliveUrl() : null, - 'releases' => $conf->hasReleases() ? $conf->getReleasesUrl() : null, - - 'CONFIG' => $GLOBALS['CONFIG'], - ]; - unset($GLOBALS['CONFIG']); + if(!is_array($config)) { + throw new ConfigException("Loading $configfile did not return an array. Maybe it's missing a return-statement?"); + } - if(isset($saved_config)) - $GLOBALS['CONFIG'] = $saved_config; + return $config; + } - return $info; + public static function getConference($mandator) { + return new Conference(Conferences::loadConferenceConfig($mandator), $mandator); } public static function hasCustomStyles($mandator) { @@ -96,9 +96,4 @@ class Conferences extends ModelBase public static function getCustomStylesDir($mandator) { return forceslash(Conferences::MANDATOR_DIR).forceslash($mandator); } - - public static function load($mandator) { - include(forceslash(Conferences::MANDATOR_DIR).forceslash($mandator).'config.php'); - return isset($GLOBALS['CONFIG']); - } } |