-
Notifications
You must be signed in to change notification settings - Fork 0
/
plistClasses.php
109 lines (92 loc) · 2.04 KB
/
plistClasses.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
<?php
class Quiz
{
public $questionSets = Array();
public $name = "";
function addQuestionSet($questionSet)
{
$this->questionSets[] = $questionSet;
}
function buildString()
{
$outStr = "";
$outStr .= "<key>" . $this->name ."</key>\n";
$outStr .= "<dict>\n";
foreach($this->questionSets as $key => $questionSet)
{
$questionSet->name = "Questions" . ($key+1);
$outStr .= $questionSet->buildString();
}
$outStr .= "</dict>\n";
return $outStr;
}
}
class QuestionSet
{
public $questions = Array();
public $name = "";
function addQuestion($question)
{
$this->questions[] = $question;
}
function buildString()
{
$outStr = "";
$outStr .= " <key>" . $this->name ."</key>\n";
$outStr .= " <array>\n";
foreach($this->questions as $question)
{
$outStr .= " <dict>\n";
$outStr .= $question->buildString();
$outStr .= " </dict>\n";
}
$outStr .= " </array>\n";
return $outStr;
}
}
class Question
{
public $choiceStr;
public $c1;
public $c2;
public $c3;
public $c4;
public $correct;
function buildString()
{
$outStr = "";
switch($this->correct){
case 1:
$this->c1 = "*" . $this->c1;
break;
case 2:
$this->c2 = "*" . $this->c2;
break;
case 3:
$this->c3 = "*" . $this->c3;
break;
case 4:
$this->c4 = "*" . $this->c4;
break;
}
$outStr .= " <key>Choices</key>\n";
$outStr .= " <array>\n";
$outStr .= " <string>" . $this->c1 ."</string>\n";
$outStr .= " <string>" . $this->c2 ."</string>\n";
$outStr .= " <string>" . $this->c3 ."</string>\n";
$outStr .= " <string>" . $this->c4 ."</string>\n";
$outStr .= " </array>\n";
$outStr .= " <key>Question</key>\n";
$outStr .= " <string>" . $this->choiceStr . "</string>\n";
return $outStr;
}
}
function genRandomString($length = 5) {
$characters = "0123456789abcdefghijklmnopqrstuvwxyz";
$string = "";
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters) - 1)];
}
return $string;
}
?>