-
Notifications
You must be signed in to change notification settings - Fork 109
/
Conferences.php
191 lines (154 loc) · 5.01 KB
/
Conferences.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php
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(Conferences::listConferences() as $conference)
{
try {
$conferences[$conference] = Conferences::getConference($conference);
}
catch(Exception $e) {
// ignore unloadable conferences
}
}
return $conferences;
}
public static function getConferencesCount() {
return count(Conferences::listConferences());
}
public static function getActiveConferences() {
return array_values(array_filter(
Conferences::getConferencesSorted(),
function($conference) {
return !$conference->isClosed() && !$conference->isUnlisted();
}
));
}
public static function getActiveConferencesCount() {
return count(Conferences::getActiveConferences());
}
public static function getConferencesSorted() {
$sorted = Conferences::getConferences();
usort($sorted, function($a, $b) {
return $b->startsAt() > $a->startsAt() ? 1 : -1;
});
return $sorted;
}
public static function getFinishedConferencesSorted() {
$sorted = Conferences::getConferencesSorted();
$finished = array_values(array_filter($sorted, function($c) {
return $c->hasEnded();
}));
return $finished;
}
public static function getLastConference() {
$conferences = Conferences::getFinishedConferencesSorted();
return isset($conferences[0]) ? $conferences[0] : null;
}
public static function exists($mandator) {
return in_array($mandator, Conferences::listConferences());
}
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) {
// try to find config.json for this conference/mandator in local configs
$configfile = forceslash(Conferences::MANDATOR_DIR).forceslash($mandator).'config.json';
if (file_exists($configfile)) {
$data = file_get_contents($configfile);
$config = json_decode(strip_comments($data));
if(is_null($config)) {
throw new ConfigException("Loading $configfile did not return an object. Maybe it's not a real JSON file? \n" . json_last_error_msg());
}
return new ConferenceJson($config, $mandator);
}
// try to find config.php for this conference/mandator in local configs
$configfile = forceslash(Conferences::MANDATOR_DIR).forceslash($mandator).'config.php';
if (file_exists($configfile)) {
$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 new Conference($config, $mandator);
}
// config option for dynamic lookup feature defined below
if (isset($GLOBALS['CONFIG']['DYNAMIC_LOOKUP']) && !$GLOBALS['CONFIG']['DYNAMIC_LOOKUP']) {
throw new NotFoundException();;
}
try {
// otherwise try to find conference in c3data postgres
$query = 'query StreamingConfig($acronym: String!) {
conference(acronym: $acronym) {
title
acronym
description
keywords
organizer
start: startDate
end: endDate
streamingConfig
rooms(orderBy: [RANK_ASC, NAME_ASC]' . (
true ? ', filter: {streamId: {isNull: false}}' : ''
) . ' ) {
nodes {
guid
name
slug
streamId
streamingConfig
}
}
}
}';
$data = query_data('conferenceConfig', $query, ['acronym' => $mandator]);
return new ConferenceJson($data, $mandator);
}
catch(Exception $e) {
throw new NotFoundException();
}
}
public static function getConference($mandator) {
return Conferences::loadConferenceConfig($mandator);
}
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);
}
}