-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgameFunction.php
More file actions
171 lines (132 loc) · 3.88 KB
/
gameFunction.php
File metadata and controls
171 lines (132 loc) · 3.88 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
require_once('gameCallURL.php');
require_once('SequenceVO.php');
require_once('StyleVO.php');
require_once('SequenceChildVO.php');
require_once('Parser.php');
require_once('SequenceHTMLFormatter.php');
require_once('HTMLContentFormatter.php');
require_once('CategorizeHTMLFormatter.php');
/**
* This functions forms the HTML content with the XML content that needs to be displayed
*
* @param unknown $dataContent
* @param unknown $styleContent
* @return string containing HTML content
*/
function formHTMLContent($dataVO,$styleVO){
if ($dataVO->getGameType() == 'SEQUENCE'){
try{
$sequenceHTMLFormatter = new SequenceHTMLFormatter();
$htmlFormatter = new HTMLContentFormatter();
$htmlFormatter->setHTMLFormatterObject($sequenceHTMLFormatter);
// Forms the various sections of the HTML document.
$headerContent = $htmlFormatter->formHeaderSection($dataVO, $styleVO);
$instructionContent = $htmlFormatter->formInstructionSection($dataVO, $styleVO);
$gameContent = $htmlFormatter->formGameSection($dataVO, $styleVO);
}catch(Exception $e){
throw $e;
}
}else if($dataVO->getGameType() == 'CATEGORIZE'){
try{
$categorizeHTMLFormatter = new CategorizeHTMLFormatter();
$htmlFormatter = new HTMLContentFormatter();
$htmlFormatter->setHTMLFormatterObject($categorizeHTMLFormatter);
// Forms the various sections of the HTML document.
$headerContent = $htmlFormatter->formHeaderSection($dataVO, $styleVO);
$instructionContent = $htmlFormatter->formInstructionSection($dataVO, $styleVO);
$gameContent = $htmlFormatter->formGameSection($dataVO, $styleVO);
}catch(Exception $e){
throw $e;
}
}
/*
* Creates a HTML content with the data xml and style xml embedded in it.
* Returns the HTML content as a string to the caller.
*/
$htmlContent =<<<FILECONTENT
<html>
<head>
$headerContent
</head>
<body onload="setHeight()">
$instructionContent
$gameContent
</body>
</html>
FILECONTENT;
return $htmlContent;
}
function formDefaultHTMLContent($dataContent,$styleContent){
/*
* Creates a HTML content with the data xml and style xml embedded in it.
* Returns the HTML content as a string to the caller.
*/
$result =<<<FILECONTENT
<html>
<head>
<title>WGS game</title>
</head>
<body>
<h1>This is a WGS game</h1>
<h2>Data file:</h2>
<pre>
$dataContent
</pre>
<h2>Style file:</h2>
<pre>
$styleContent
</pre>
<body>
<html>
FILECONTENT;
return $result;
}
/**
* This function receives the dataUri, styleUri. Fetches the XML content using the URI.
* Creates an HTML page with the contents of the XML and displays it.
*
* @param unknown $dataUri
* @param unknown $styleUri
* @param string $formatOverride
* @return string containing HTML content
*/
function game ($dataUri, $styleUri, $formatOverride = FALSE){
/*
* Checks if the data URL and style is null is not null.
* If null, an appropriate exception is thrown.
*
*/
if(is_null($dataUri)){
exit("Data URI is NULL");
}
if(is_null($styleUri)){
exit("Style URI is NULL");
}
/*
* Calls the gameCallURL function to fetch the contents of data and style xml.
*
*/
try{
$dataURLContent = gameCallURL($dataUri);
$styleURLContent = gameCallURL($styleUri);
/*
* Parse the data and style xmls and form a html string using the data and style VO objects
*
*/
$dataVO = parseDataFile($dataURLContent);
$styleVO = parseStyleFile($styleURLContent);
/*
* Forms the HTML Section for the game.
*
*/
$htmlContent = formHTMLContent($dataVO,$styleVO);
}catch(Exception $e){
$htmlContent = formDefaultHTMLContent(htmlspecialchars($dataURLContent),htmlspecialchars($styleURLContent));
}
/*
* returns the html string to the caller.
*/
return $htmlContent;
}
?>