-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path06_quiz_generator.php
More file actions
70 lines (50 loc) · 2.13 KB
/
Copy path06_quiz_generator.php
File metadata and controls
70 lines (50 loc) · 2.13 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
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
<?php
$vers = 2;
$scale_root ="SimV".$vers;
ini_set("display_errors", "1");
error_reporting(E_ALL);
set_time_limit(0);
require_once ("00_functions.php");
require_once ("Daten/items V".$vers.".php");
// Einlesen der Datei mit den Daten für die Fragen
$question_data = [];
foreach ($items as $scale_id => $scale) {
foreach ($scale as $item_id => $item) {
$question_data[] = ['ID' => "V".$vers."-".$item_id, 'a' => $item['a'], 'b' => $item['b'], 'scale' => $scale_id];
}
}
// Generiere Question-Export
// Einlesen des Grund-Templates
$question_export = file_get_contents("QType-Template/template.xml");
$question_output = "";
foreach ($question_data as $n => $question) {
// Prüfe auf Vollständigkeit
foreach ($question as $key => $value) {
if ($value == "") {
echo "<b>Fehler: </b>Angaben unvollständig zu '$key' in Zeile <b>". ($n+3) ."</b>. Eintrag wird nicht bearbeitet.<br>";
continue(2);
}
}
// Lese Template ein
$question_template = file_get_contents("QType-Template/singlechoice.xml");
// Erfasse alle grundlegenden Daten
$search = [];
$replace = [];
$search[] = "{{Datum}}"; $replace[] = date("Y-m-d");
foreach ($question as $key => $value) {
if ($value !== "") {
$search[] = "{{" . $key . "}}"; $replace[] = trim($value);
}
}
$question_template = str_replace ($search, $replace, $question_template);
$question_output .= $question_template;
}
$question_export = str_replace(["{{output}}"], [$question_output], $question_export);
file_put_contents("Ergebnisse/export_questionbank V".$vers.".xml", $question_export);
// Generiere Scale-Export
$scale_export = "componentid,componentname,contextid,status,qtype,model,difficulty,discrimination,guessing,label,catscalename,parentscalenames";
foreach ($question_data as $n => $question) {
$scale_export .="\n0,question,1,4,Multiple-Choice,raschbirnbaumb,".round($question['a'],2).",".round($question['b'],2).",0.00,SIM".$question['ID'].",Sim".substr($question['scale'], 2, 3).",".$scale_root."|Sim".substr($question['scale'], 0,1);
}
file_put_contents("Ergebnisse/export_CATscales V".$vers.".csv", $scale_export);
echo "Fertig.";