-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.php
More file actions
41 lines (36 loc) · 1.11 KB
/
Copy pathindex.php
File metadata and controls
41 lines (36 loc) · 1.11 KB
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
<?php
require 'vendor/autoload.php';
session_start();
$service = new \QuizApp\Service\Quiz(
new \QuizApp\Mapper\Mongo((new \MongoClient)->practicaloop->quizes)
);
$app = new \Slim\Slim();
$app->config(array('templates.path' => './views'));
$app->get('/', function () use ($service, $app) {
$app->render('choose-quiz.phtml', array(
'quizes' => $service->showAllQuizes(),
));
});
$app->get('/choose-quiz/:id', function ($id) use ($service, $app) {
$service->startQuiz($id);
$app->redirect('/solve-question');
});
$app->get('/solve-question', function () use ($service, $app) {
$app->render('solve-question.phtml', array(
'question' => $service->getQuestion(),
));
});
$app->post('/check-answer', function () use ($service, $app) {
$isCorrect = $service->checkSolution($app->request->post('id'));
if (!$service->isOver()) {
$app->redirect('/solve-question');
} else {
$app->redirect('/end');
}
});
$app->get('/end', function () use ($service, $app) {
$app->render('end.phtml', array(
'result' => $service->getResult(),
));
});
$app->run();