-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
61 lines (52 loc) · 1.78 KB
/
index.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
<?php
use Brus\Session;
use AstroQuiz\ConfigureFile;
use AstroQuiz\QuestionFile;
use AstroQuiz\DatabaseFile;
use AstroQuiz\Question;
require_once __DIR__.'/vendor/autoload.php';
Session::start();
$loader = new Twig_Loader_Filesystem(__DIR__.'/templates');
$twig = new Twig_Environment($loader);
$loadDataCorrectly = TRUE;
$loadDataError = NULL;
try {
$configureFile = new ConfigureFile("astroquiz.cfg");
$fileWithQuestions = $configureFile->getFilenameWithQuestions();
$questionFile = new QuestionFile("files/" . $fileWithQuestions);
$databaseFile = new DatabaseFile("database/database", "r+");
} catch (AstroQuiz\Exception\WrongConfiguration $err) {
$loadDataCorrectly = FALSE;
$loadDataError = $err->getMessage();
} catch (Brus\Exception\NoFileException $err) {
$loadDataCorrectly = FALSE;
$loadDataError = $err->getMessage();
} catch (Brus\Exception\NoFileAccessException $err) {
$loadDataCorrectly = FALSE;
$loadDataError = $err->getMessage();
}
if ($loadDataCorrectly === FALSE) {
echo $twig->render('index.html.twig', array(
'loadDataError' => $loadDataError
));
exit;
}
if ($questionFile->properSize() === FALSE) {
$loadDataError = $questionFile->error();
} else {
$amountQuestions = $questionFile->amountQuestions();
$allQuestions = array();
$currentQuestionIndex = 0;
for ($i = 0; $i < $amountQuestions; $i++) {
$allQuestions[$i] = new Question($questionFile->readQuestion());
}
Session::addVar(array(
'amountQuestions' => $amountQuestions,
'allQuestions' => $allQuestions,
'currentQuestionIndex' => $currentQuestionIndex,
'imageWidth' => $configureFile->getImagesWidth()
));
}
echo $twig->render('index.html.twig', array(
'loadDataError' => $loadDataError
));