-
Notifications
You must be signed in to change notification settings - Fork 1
/
questions_mng.php
136 lines (121 loc) · 5.48 KB
/
questions_mng.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
<?php
class QuestionsManager {
public $answers;
private $json;
function __construct() {
$this->json = json_decode(file_get_contents('model/questions.json'), true);
$this->populate_answers();
}
function get_questions() {
//$content = file_get_contents('model/questions.json');
//$json = json_decode($content, true);
foreach($this->json['questions'] as $key => $value) {
print "<li>
<div class=\"form-group\">
<label class=\"q_title\">({$value["source"]}) {$value["text"]}</label>
<div class=\"input-group mb-3\">
<div class=\"input-group-prepend\">
<div class=\"input-group-text\">
<input type=\"radio\" name=\"question_{$key}_answer\" id=\"q{$key}_a\" value=\"a\"/>
</div>
</div>
<label class=\"form-control\" for=\"q{$key}_a\">A) {$value["alternatives"]["a"][0]}</label>
</div>
<div class=\"input-group mb-3\">
<div class=\"input-group-prepend\">
<div class=\"input-group-text\">
<input type=\"radio\" name=\"question_{$key}_answer\" id=\"q{$key}_b\" value=\"b\"/>
</div>
</div>
<label class=\"form-control\" for=\"q{$key}_b\">B) {$value["alternatives"]["b"][0]}</label>
</div>
<div class=\"input-group mb-3\">
<div class=\"input-group-prepend\">
<div class=\"input-group-text\">
<input type=\"radio\" name=\"question_{$key}_answer\" id=\"q{$key}_c\" value=\"c\"/>
</div>
</div>
<label class=\"form-control\" for=\"q{$key}_c\">C) {$value["alternatives"]["c"][0]}</label>
</div>
<div class=\"input-group mb-3\">
<div class=\"input-group-prepend\">
<div class=\"input-group-text\">
<input type=\"radio\" name=\"question_{$key}_answer\" id=\"q{$key}_d\" value=\"d\"/>
</div>
</div>
<label class=\"form-control\" for=\"q{$key}_d\">D) {$value["alternatives"]["d"][0]}</label>
</div>
<div class=\"input-group mb-3\">
<div class=\"input-group-prepend\">
<div class=\"input-group-text\">
<input type=\"radio\" name=\"question_{$key}_answer\" id=\"q{$key}_e\" value=\"e\"/>
</div>
</div>
<label class=\"form-control\" for=\"q{$key}_e\">E) {$value["alternatives"]["e"][0]}</label>
</div>
</div>
</li>";
}
}
function get_result($results) {
$final_answer = [];
$final_score = 0;
foreach ($results as $key => $value) {
switch ($value) {
case 'a':
$sequence = array(1,0,0,0,0);
break;
case 'b':
$sequence = array(0,1,0,0,0);
break;
case 'c':
$sequence = array(0,0,1,0,0);
break;
case 'd':
$sequence = array(0,0,0,1,0);
break;
case 'e':
$sequence = array(0,0,0,0,1);
break;
default:
break;
}
array_push($final_answer, $sequence);
}
for($i=0;$i<10;$i++) {
for($j=0;$j<5;$j++) {
if($this->answers[$i][$j] and $final_answer[$i][$j] == 1)
$final_score++;
}
}
return $final_score;
}
function populate_answers() {
$alternative = "";
foreach ($this->json["questions"] as $key => $value) {
for($i=0;$i<5;$i++) {
switch ($i) {
case 0:
$alternative = "a";
break;
case 1:
$alternative = "b";
break;
case 2:
$alternative = "c";
break;
case 3:
$alternative = "d";
break;
case 4:
$alternative = "e";
break;
default:
break;
}
$this->answers[$key][$i] = $value["alternatives"][$alternative][1] == 1 ? 1 : 0;
}
}
}
}
?>