aboutsummaryrefslogtreecommitdiff
path: root/model/Conferences.php
blob: f7276acab1d93e605cea8e489a6a522ac66e486e (plain)
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
<?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();
			}
		));
	}

	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() {
		return Conferences::getFinishedConferencesSorted()[0];
	}

	public static function exists($mandator) {
		return in_array($mandator, Conferences::listConferences());
	}

	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?");
		}

		return $config;
	}

	public static function getConference($mandator) {
		return new Conference(Conferences::loadConferenceConfig($mandator), $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);
	}
}