2015-11-08 13:40:30 +00:00
|
|
|
<?php
|
|
|
|
|
2016-12-11 18:56:36 +00:00
|
|
|
class Conferences
|
2015-11-08 13:40:30 +00:00
|
|
|
{
|
|
|
|
const MANDATOR_DIR = 'configs/conferences/';
|
|
|
|
|
2016-12-10 17:22:34 +00:00
|
|
|
public static function listConferences() {
|
|
|
|
$directories = scandir(forceslash(Conferences::MANDATOR_DIR));
|
|
|
|
$conferences = array_filter($directories, function($dirname) {
|
|
|
|
return $dirname[0] != '.';
|
|
|
|
});
|
|
|
|
|
|
|
|
return $conferences;
|
|
|
|
}
|
|
|
|
|
2015-11-08 13:40:30 +00:00
|
|
|
public static function getConferences() {
|
2015-11-08 15:31:29 +00:00
|
|
|
$conferences = [];
|
2016-12-10 17:22:34 +00:00
|
|
|
foreach(Conferences::listConferences() as $conference)
|
2015-11-08 15:31:29 +00:00
|
|
|
{
|
2016-12-10 17:22:34 +00:00
|
|
|
try {
|
|
|
|
$conferences[$conference] = Conferences::getConference($conference);
|
|
|
|
}
|
|
|
|
catch(Exception $e) {
|
|
|
|
// ignore unloadable conferences
|
|
|
|
}
|
2015-11-08 15:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $conferences;
|
2015-11-08 13:40:30 +00:00
|
|
|
}
|
|
|
|
public static function getConferencesCount() {
|
2016-12-10 17:22:34 +00:00
|
|
|
return count(Conferences::listConferences());
|
2015-11-08 13:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function getActiveConferences() {
|
|
|
|
return array_values(array_filter(
|
2016-12-11 19:27:58 +00:00
|
|
|
Conferences::getConferencesSorted(),
|
2016-12-10 17:22:34 +00:00
|
|
|
function($conference) {
|
|
|
|
return !$conference->isClosed();
|
2015-11-08 15:31:29 +00:00
|
|
|
}
|
2015-11-08 13:40:30 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getActiveConferencesCount() {
|
|
|
|
return count(Conferences::getActiveConferences());
|
|
|
|
}
|
|
|
|
|
2015-12-30 22:08:19 +00:00
|
|
|
public static function getConferencesSorted() {
|
|
|
|
$sorted = Conferences::getConferences();
|
|
|
|
|
|
|
|
usort($sorted, function($a, $b) {
|
2017-05-28 11:00:54 +00:00
|
|
|
return $b->startsAt() > $a->startsAt() ? 1 : -1;
|
2015-12-30 22:08:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return $sorted;
|
|
|
|
}
|
|
|
|
|
2016-01-17 11:28:19 +00:00
|
|
|
public static function getFinishedConferencesSorted() {
|
|
|
|
$sorted = Conferences::getConferencesSorted();
|
|
|
|
|
|
|
|
$finished = array_values(array_filter($sorted, function($c) {
|
2016-12-10 17:22:34 +00:00
|
|
|
return $c->hasEnded();
|
2016-01-17 11:28:19 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
return $finished;
|
|
|
|
}
|
|
|
|
|
2015-12-30 22:08:19 +00:00
|
|
|
public static function getLastConference() {
|
2016-01-17 11:28:19 +00:00
|
|
|
return Conferences::getFinishedConferencesSorted()[0];
|
2015-12-30 22:08:19 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 13:40:30 +00:00
|
|
|
public static function exists($mandator) {
|
2016-12-10 17:22:34 +00:00
|
|
|
return in_array($mandator, Conferences::listConferences());
|
2015-11-08 13:40:30 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 18:50:55 +00:00
|
|
|
private static function migrateTranslationConfiguration($config) {
|
|
|
|
// Allow setting TRANSLATION simply to true and fill in default values for uniformity
|
|
|
|
$rooms = $config['ROOMS'];
|
|
|
|
foreach ($rooms as $slug => $room) {
|
|
|
|
// Translation is commented out, equaivalent of false
|
|
|
|
if (!isset($room['TRANSLATION'])) {
|
|
|
|
$config['ROOMS'][$slug]['TRANSLATION'] = [];
|
|
|
|
}
|
|
|
|
// Translation is present but not an array
|
|
|
|
elseif (! is_array($room['TRANSLATION'])) {
|
|
|
|
// Translation is true, set default values
|
|
|
|
if ($room['TRANSLATION'] === true) {
|
|
|
|
$config['ROOMS'][$slug]['TRANSLATION'] = [[
|
|
|
|
'endpoint' => 'translated',
|
|
|
|
'label' => 'Translated'
|
|
|
|
]];
|
|
|
|
}
|
|
|
|
// Translation is false or garbage
|
|
|
|
else {
|
|
|
|
$config['ROOMS'][$slug]['TRANSLATION'] = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $config;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function loadConferenceConfig($mandator) {
|
|
|
|
$configfile = forceslash(Conferences::MANDATOR_DIR).forceslash($mandator).'config.php';
|
|
|
|
$config = include($configfile);
|
|
|
|
|
|
|
|
if(!is_array($config)) {
|
|
|
|
throw new ConfigException("Loading $configfile did not return an array. Maybe it's missing a return-statement?");
|
|
|
|
}
|
|
|
|
|
|
|
|
$config = Conferences::migrateTranslationConfiguration($config);
|
|
|
|
|
|
|
|
return $config;
|
|
|
|
}
|
2015-11-08 13:40:30 +00:00
|
|
|
|
2016-12-10 17:22:34 +00:00
|
|
|
public static function getConference($mandator) {
|
|
|
|
return new Conference(Conferences::loadConferenceConfig($mandator), $mandator);
|
2015-11-08 13:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function hasCustomStyles($mandator) {
|
|
|
|
return file_exists(Conferences::getCustomStyles($mandator));
|
|
|
|
}
|
|
|
|
public static function getCustomStyles($mandator) {
|
|
|
|
return forceslash(Conferences::getCustomStylesDir($mandator)).'main.less';
|
|
|
|
}
|
|
|
|
public static function getCustomStylesDir($mandator) {
|
|
|
|
return forceslash(Conferences::MANDATOR_DIR).forceslash($mandator);
|
|
|
|
}
|
|
|
|
}
|