1
|
/****************************************************************************
|
2
|
* Multiple Assessment download
|
3
|
* @param form containing the neceassary input items
|
4
|
* @return true/false for form submission
|
5
|
*****************************************************************************/
|
6
|
function multipleAssessmentSearch(submitFormObj) {
|
7
|
|
8
|
//harvest the metadata fields we want to include
|
9
|
var metadataObjs = new Array();
|
10
|
/*
|
11
|
var index = 0;
|
12
|
for (var i=0; i < submitFormObj.length; i++) {
|
13
|
var formElement = submitFormObj.elements[i];
|
14
|
if (formElement.type == "checkbox" && formElement.checked) {
|
15
|
//ignore certain other checkboxes, kind of a hack
|
16
|
if (formElement.name == "includeQuestions") {
|
17
|
continue;
|
18
|
}
|
19
|
var metadataObj = new Object();
|
20
|
metadataObj.name = formElement.name;
|
21
|
metadataObj.value = formElement.value;
|
22
|
metadataObjs[index] = metadataObj;
|
23
|
index++;
|
24
|
}
|
25
|
}
|
26
|
*/
|
27
|
|
28
|
//TODO option for all questions vs. just one
|
29
|
var questionId = submitFormObj.questionId.value;
|
30
|
//alert("questionId=" + questionId);
|
31
|
var questionIds = new Array();
|
32
|
questionIds[0] = questionId;
|
33
|
|
34
|
var documentObjects = new Array();
|
35
|
|
36
|
if (submitFormObj.docids.length > 1) {
|
37
|
for (var i=0; i < submitFormObj.docids.length; i++) {
|
38
|
var documentObject = new Object();
|
39
|
documentObject.docid = submitFormObj.docids[i].value;
|
40
|
documentObject.questionIds = questionIds;
|
41
|
documentObjects[i] = documentObject;
|
42
|
}
|
43
|
}
|
44
|
else {
|
45
|
var documentObject = new Object();
|
46
|
documentObject.docid = submitFormObj.docids.value;
|
47
|
for (var z = 0; z < submitFormObj[documentObject.docid].length; z++) {
|
48
|
questionIds[z] = submitFormObj[documentObject.docid][z].value;
|
49
|
}
|
50
|
documentObject.questionIds = questionIds;
|
51
|
documentObjects[0] = documentObject;
|
52
|
}
|
53
|
|
54
|
var query = generateQuery(documentObjects, metadataObjs);
|
55
|
|
56
|
submitFormObj.dataquery.value = query;
|
57
|
|
58
|
return true;
|
59
|
|
60
|
}
|
61
|
|
62
|
/****************************************************************************
|
63
|
* Single Assessment download
|
64
|
* @param form containing the neceassary input items
|
65
|
* @return true/false for form submission
|
66
|
*****************************************************************************/
|
67
|
function assessmentSearch(submitFormObj) {
|
68
|
|
69
|
//harvest the metadata fields we want to include
|
70
|
var metadataObjs = new Array();
|
71
|
var index = 0;
|
72
|
for (var i=0; i < submitFormObj.length; i++) {
|
73
|
var formElement = submitFormObj.elements[i];
|
74
|
if (formElement.type == "checkbox" && formElement.checked) {
|
75
|
//ignore certain other checkboxes, kind of a hack
|
76
|
if (formElement.name == "includeQuestions") {
|
77
|
continue;
|
78
|
}
|
79
|
var metadataObj = new Object();
|
80
|
metadataObj.name = formElement.name;
|
81
|
metadataObj.value = formElement.value;
|
82
|
metadataObjs[index] = metadataObj;
|
83
|
index++;
|
84
|
}
|
85
|
}
|
86
|
|
87
|
//var checkBox = document.getElementById("searchAll");
|
88
|
var docId = submitFormObj.docid.value;
|
89
|
//alert("docId=" + docId);
|
90
|
|
91
|
//do we want question metadata?
|
92
|
var includeQuestions = submitFormObj.includeQuestions.checked;
|
93
|
var questionIds = new Array();
|
94
|
questionIds[0] = "";
|
95
|
|
96
|
if (includeQuestions) {
|
97
|
if (submitFormObj.assessmentItemId.length > 1) {
|
98
|
for (var i=0; i < submitFormObj.assessmentItemId.length; i++) {
|
99
|
questionIds[i] = submitFormObj.assessmentItemId[i].value;
|
100
|
}
|
101
|
}
|
102
|
else {
|
103
|
questionIds[0] = submitFormObj.assessmentItemId.value;
|
104
|
}
|
105
|
}
|
106
|
|
107
|
//set up the list of objects to pass to the query assembler, just one document
|
108
|
var documentObjects = new Array();
|
109
|
var documentObject = new Object();
|
110
|
documentObject.docid = docId;
|
111
|
documentObject.questionIds = questionIds;
|
112
|
documentObjects[0] = documentObject;
|
113
|
|
114
|
var query = generateQuery(documentObjects, metadataObjs);
|
115
|
|
116
|
submitFormObj.dataquery.value = query;
|
117
|
|
118
|
return true;
|
119
|
|
120
|
}
|
121
|
|
122
|
/****************************************************************************
|
123
|
* Query Generation function
|
124
|
* @param docObjs is an Array of Objects with "docid" (String) and "questionIds" (Array) properties
|
125
|
* @param metadataObjs is an Array of Objects with "name" and "value" properties (both String)
|
126
|
* @return generated query string
|
127
|
*****************************************************************************/
|
128
|
function generateQuery(docObjs, metadataObjs) {
|
129
|
//alert("calling method");
|
130
|
|
131
|
//construct the assessment metadata attribute selection snippet
|
132
|
var metadataAttributes = "";
|
133
|
var index = 0;
|
134
|
for (var j=0; j < metadataObjs.length; j++) {
|
135
|
var metadataObj = metadataObjs[j];
|
136
|
|
137
|
metadataAttributes += "<attribute index=\"";
|
138
|
metadataAttributes += index;
|
139
|
metadataAttributes += "\">";
|
140
|
|
141
|
metadataAttributes += "<pathexpr label=\"";
|
142
|
metadataAttributes += metadataObj.name;
|
143
|
metadataAttributes += "\">";
|
144
|
metadataAttributes += metadataObj.value;
|
145
|
metadataAttributes += "</pathexpr>";
|
146
|
|
147
|
metadataAttributes += "</attribute>";
|
148
|
|
149
|
index++;
|
150
|
}//metadataObjs loop
|
151
|
|
152
|
|
153
|
//construct the begining of the query
|
154
|
var tempQuery =
|
155
|
"<?xml version=\"1.0\"?>"
|
156
|
+ "<dataquery>"
|
157
|
+ "<union>";
|
158
|
|
159
|
for (var i=0; i < docObjs.length; i++) {
|
160
|
|
161
|
var docId = docObjs[i].docid;
|
162
|
alert("docId=" + docId);
|
163
|
|
164
|
//get the question ids for this question
|
165
|
var questionIds = docObjs[i].questionIds;
|
166
|
|
167
|
alert("questionIds=" + questionIds);
|
168
|
|
169
|
//assemble the assessment metadata
|
170
|
var metadataAttributeSelection = "";
|
171
|
if (metadataAttributes.length > 0) {
|
172
|
metadataAttributeSelection =
|
173
|
"<datapackage id=\"" + docId + "\">"
|
174
|
+ "<entity id=\"" + docId + "\">"
|
175
|
+ metadataAttributes
|
176
|
+ "</entity>"
|
177
|
+ "</datapackage>";
|
178
|
}
|
179
|
|
180
|
//loop for each question item
|
181
|
for (var k=0; k < questionIds.length; k++) {
|
182
|
var questionId = questionIds[k];
|
183
|
|
184
|
tempQuery +=
|
185
|
"<query>"
|
186
|
//select the data
|
187
|
+ "<selection>"
|
188
|
+ "<datapackage id=\"" + docId + "\">"
|
189
|
+ "<entity index=\"0\">"
|
190
|
+ "<attribute index=\"0\"/>"
|
191
|
+ "<attribute index=\"1\"/>"
|
192
|
//omit student id attribute
|
193
|
+ "<attribute index=\"3\"/>"
|
194
|
+ "<attribute index=\"4\"/>"
|
195
|
+ "</entity>"
|
196
|
+ "</datapackage>";
|
197
|
|
198
|
//select the metadata
|
199
|
tempQuery += metadataAttributeSelection;
|
200
|
|
201
|
//select the question metadata
|
202
|
if (questionId.length > 0) {
|
203
|
tempQuery +=
|
204
|
"<datapackage id=\"" + questionId + "\">"
|
205
|
+ "<entity id=\"" + questionId + "\">"
|
206
|
+ "<attribute index=\"0\">"
|
207
|
+ "<pathexpr label=\"qId\">//assessment/section/item/@ident</pathexpr>"
|
208
|
+ "</attribute>"
|
209
|
+ "<attribute index=\"1\">"
|
210
|
+ "<pathexpr label=\"qTitle\">//assessment/section/item/@title</pathexpr>"
|
211
|
+ "</attribute>"
|
212
|
+ "<attribute index=\"2\">"
|
213
|
+ "<pathexpr label=\"qLabel\">//assessment/section/item/presentation/@label</pathexpr>"
|
214
|
+ "</attribute>"
|
215
|
+ "</entity>"
|
216
|
+ "</datapackage>";
|
217
|
}
|
218
|
|
219
|
tempQuery += "</selection>";
|
220
|
|
221
|
//join to the quesion "table"
|
222
|
if (questionId.length > 0) {
|
223
|
tempQuery +=
|
224
|
"<where>"
|
225
|
+ "<condition type=\"join\">"
|
226
|
+ "<left>"
|
227
|
+ "<datapackage id=\"" + docId + "\">"
|
228
|
+ "<entity index=\"0\">"
|
229
|
+ "<attribute index=\"1\"/>"
|
230
|
+ "</entity>"
|
231
|
+ "</datapackage>"
|
232
|
+ "</left>"
|
233
|
+ "<operator>=</operator>"
|
234
|
+ "<right>"
|
235
|
+ "<datapackage id=\"" + questionId + "\">"
|
236
|
+ "<entity id=\"" + questionId + "\">"
|
237
|
+ "<attribute index=\"0\">"
|
238
|
+ "<pathexpr label=\"qId\">//assessment/section/item/@ident</pathexpr>"
|
239
|
+ "</attribute>"
|
240
|
+ "</entity>"
|
241
|
+ "</datapackage>"
|
242
|
+ "</right>"
|
243
|
+ "</condition>"
|
244
|
+ "</where>";
|
245
|
}
|
246
|
|
247
|
tempQuery += "</query>";
|
248
|
|
249
|
} // for questionId loop
|
250
|
|
251
|
|
252
|
} //for docObjs loop
|
253
|
|
254
|
tempQuery +=
|
255
|
"</union>"
|
256
|
+ "</dataquery>";
|
257
|
|
258
|
alert(tempQuery);
|
259
|
|
260
|
return tempQuery;
|
261
|
}
|