-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
84 lines (76 loc) · 3.06 KB
/
test.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
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1, shrink-to-fit=no'>
<link rel="stylesheet" href="./css/index.css">
<title>Главная</title>
</head>
<?php
use Src\BeginTestRepository;
use Src\OptionRepository;
use Src\QuestionRepository;
use Src\SelectedRepository;
use Src\TestRepository;
use Src\UserRepository;
require_once './vendor/autoload.php';
auth();
$userRep = new UserRepository();
$testRep = new TestRepository();
$bgtRep = new BeginTestRepository();
$test = $testRep->find($_GET['id']);
$user = $userRep->findById($test['user_id']);
$bgt = $bgtRep->findById($test['id'], $_SESSION['id'])
?>
<body>
<header class="header">
<p><?=$_SESSION['email']?></p>
<div>
<a href="/">Главная</a>
<a href="/action/auth/exit.php">Выход</a>
</div>
</header>
<div class="container">
<div class="content-home">
<?php if ($bgt and $bgt['finished_at'] == null): ?>
<div class="description">
<h3>Теста</h3>
<p>Название: <?= $test['title'] ?></p>
<p>Описание: <?= $test['description'] ?></p>
<p>Автор: <?= $user['email'] ?></p>
<a href="/test/begin.php?id=<?=$test['id']?>">Продолжить</a>
</div>
<?php elseif($bgt):?>
<?php
$optionsRep = new OptionRepository();
$selectedRep = new SelectedRepository();
$countValidOptions = $optionsRep->countOptionsIsValid($bgt['test_id'])[0];
$countInvalidOptions = $optionsRep->countOptionsIsInvalid($bgt['test_id'])[0];
$countSelectValid = $selectedRep->countSelectedIsValid($bgt['id'])[0];
$countSelectInvalid = $selectedRep->countSelectedIsInvalid($bgt['id'])[0];
$percent = ($countSelectValid/$countValidOptions - $countSelectInvalid/$countInvalidOptions)*100;
$percentTotal = 0;
if ($percent > 0) $percentTotal = $percent;
?>
<div class="description">
<input type="hidden" name="user_id" value="<?=$_SESSION['id']?>">
<h3>Результат теста</h3>
<p>Название: <?= $test['title'] ?></p>
<p>Описание: <?= $test['description'] ?></p>
<p>Автор: <?= $user['email'] ?></p>
<p>Процент: <?=$percentTotal?>%</p>
</div>
<?php else:?>
<form class="description" method="post" action="/action/begin/create.php">
<input type="hidden" name="test_id" value="<?=$_GET['id']?>">
<h3>Тест</h3>
<p>Название: <?= $test['title'] ?></p>
<p>Описание: <?= $test['description'] ?></p>
<p>Автор: <?= $user['email'] ?></p>
<button type="submit">Пройти тест</button>
</form>
<?php endif;?>
</div>
</div>
</body>
</html>