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
|
var index = 0;
|
36
|
if (submitFormObj.docids.length > 1) {
|
37
|
for (var i=0; i < submitFormObj.docids.length; i++) {
|
38
|
if (submitFormObj.docids[i].checked) {
|
39
|
var documentObject = new Object();
|
40
|
documentObject.docid = submitFormObj.docids[i].value;
|
41
|
|
42
|
for (var z = 0; z < submitFormObj[documentObject.docid].length; z++) {
|
43
|
questionIds[z] = submitFormObj[documentObject.docid][z].value;
|
44
|
}
|
45
|
|
46
|
documentObject.questionIds = questionIds;
|
47
|
documentObjects[index] = documentObject;
|
48
|
index++;
|
49
|
}
|
50
|
}
|
51
|
}
|
52
|
else {
|
53
|
if (submitFormObj.docids.checked) {
|
54
|
var documentObject = new Object();
|
55
|
documentObject.docid = submitFormObj.docids.value;
|
56
|
|
57
|
for (var z = 0; z < submitFormObj[documentObject.docid].length; z++) {
|
58
|
questionIds[z] = submitFormObj[documentObject.docid][z].value;
|
59
|
}
|
60
|
|
61
|
documentObject.questionIds = questionIds;
|
62
|
documentObjects[0] = documentObject;
|
63
|
}
|
64
|
}
|
65
|
|
66
|
var query = generateQuery(documentObjects, metadataObjs);
|
67
|
|
68
|
submitFormObj.dataquery.value = query;
|
69
|
|
70
|
return true;
|
71
|
|
72
|
}
|
73
|
|
74
|
/****************************************************************************
|
75
|
* Single Assessment download
|
76
|
* @param form containing the neceassary input items
|
77
|
* @return true/false for form submission
|
78
|
*****************************************************************************/
|
79
|
function assessmentSearch(submitFormObj) {
|
80
|
|
81
|
//harvest the metadata fields we want to include
|
82
|
var metadataObjs = new Array();
|
83
|
var index = 0;
|
84
|
for (var i=0; i < submitFormObj.length; i++) {
|
85
|
var formElement = submitFormObj.elements[i];
|
86
|
if (formElement.type == "checkbox" && formElement.checked) {
|
87
|
//ignore certain other checkboxes, kind of a hack
|
88
|
if (formElement.name == "includeQuestions") {
|
89
|
continue;
|
90
|
}
|
91
|
var metadataObj = new Object();
|
92
|
metadataObj.name = formElement.name;
|
93
|
metadataObj.value = formElement.value;
|
94
|
metadataObjs[index] = metadataObj;
|
95
|
index++;
|
96
|
}
|
97
|
}
|
98
|
|
99
|
//var checkBox = document.getElementById("searchAll");
|
100
|
var docId = submitFormObj.docid.value;
|
101
|
//alert("docId=" + docId);
|
102
|
|
103
|
//do we want question metadata?
|
104
|
var includeQuestions = submitFormObj.includeQuestions.checked;
|
105
|
var questionIds = new Array();
|
106
|
questionIds[0] = "";
|
107
|
|
108
|
if (includeQuestions) {
|
109
|
if (submitFormObj.assessmentItemId.length > 1) {
|
110
|
for (var i=0; i < submitFormObj.assessmentItemId.length; i++) {
|
111
|
questionIds[i] = submitFormObj.assessmentItemId[i].value;
|
112
|
}
|
113
|
}
|
114
|
else {
|
115
|
questionIds[0] = submitFormObj.assessmentItemId.value;
|
116
|
}
|
117
|
}
|
118
|
|
119
|
//set up the list of objects to pass to the query assembler, just one document
|
120
|
var documentObjects = new Array();
|
121
|
var documentObject = new Object();
|
122
|
documentObject.docid = docId;
|
123
|
documentObject.questionIds = questionIds;
|
124
|
documentObjects[0] = documentObject;
|
125
|
|
126
|
var query = generateQuery(documentObjects, metadataObjs);
|
127
|
|
128
|
submitFormObj.dataquery.value = query;
|
129
|
|
130
|
return true;
|
131
|
|
132
|
}
|
133
|
|
134
|
/****************************************************************************
|
135
|
* Query Generation function
|
136
|
* @param docObjs is an Array of Objects with "docid" (String) and "questionIds" (Array) properties
|
137
|
* @param metadataObjs is an Array of Objects with "name" and "value" properties (both String)
|
138
|
* @return generated query string
|
139
|
*****************************************************************************/
|
140
|
function generateQuery(docObjs, metadataObjs) {
|
141
|
//alert("calling method");
|
142
|
|
143
|
//construct the assessment metadata attribute selection snippet
|
144
|
var metadataAttributes = "";
|
145
|
var index = 0;
|
146
|
for (var j=0; j < metadataObjs.length; j++) {
|
147
|
var metadataObj = metadataObjs[j];
|
148
|
|
149
|
metadataAttributes += "<attribute index=\"";
|
150
|
metadataAttributes += index;
|
151
|
metadataAttributes += "\">";
|
152
|
|
153
|
metadataAttributes += "<pathexpr label=\"";
|
154
|
metadataAttributes += metadataObj.name;
|
155
|
metadataAttributes += "\">";
|
156
|
metadataAttributes += metadataObj.value;
|
157
|
metadataAttributes += "</pathexpr>";
|
158
|
|
159
|
metadataAttributes += "</attribute>";
|
160
|
|
161
|
index++;
|
162
|
}//metadataObjs loop
|
163
|
|
164
|
|
165
|
//construct the begining of the query
|
166
|
var tempQuery =
|
167
|
"<?xml version=\"1.0\"?>"
|
168
|
+ "<dataquery>"
|
169
|
+ "<union>";
|
170
|
|
171
|
for (var i=0; i < docObjs.length; i++) {
|
172
|
|
173
|
var docId = docObjs[i].docid;
|
174
|
alert("docId=" + docId);
|
175
|
|
176
|
//get the question ids for this question
|
177
|
var questionIds = docObjs[i].questionIds;
|
178
|
|
179
|
alert("questionIds=" + questionIds);
|
180
|
|
181
|
//assemble the assessment metadata
|
182
|
var metadataAttributeSelection = "";
|
183
|
if (metadataAttributes.length > 0) {
|
184
|
metadataAttributeSelection =
|
185
|
"<datapackage id=\"" + docId + "\">"
|
186
|
+ "<entity id=\"" + docId + "\">"
|
187
|
+ metadataAttributes
|
188
|
+ "</entity>"
|
189
|
+ "</datapackage>";
|
190
|
}
|
191
|
|
192
|
//loop for each question item
|
193
|
for (var k=0; k < questionIds.length; k++) {
|
194
|
var questionId = questionIds[k];
|
195
|
|
196
|
tempQuery +=
|
197
|
"<query>"
|
198
|
//select the data
|
199
|
+ "<selection>"
|
200
|
+ "<datapackage id=\"" + docId + "\">"
|
201
|
+ "<entity index=\"0\">"
|
202
|
+ "<attribute index=\"0\"/>"
|
203
|
+ "<attribute index=\"1\"/>"
|
204
|
//omit student id attribute
|
205
|
+ "<attribute index=\"3\"/>"
|
206
|
+ "<attribute index=\"4\"/>"
|
207
|
+ "</entity>"
|
208
|
+ "</datapackage>";
|
209
|
|
210
|
//select the metadata
|
211
|
tempQuery += metadataAttributeSelection;
|
212
|
|
213
|
//select the question metadata
|
214
|
if (questionId.length > 0) {
|
215
|
tempQuery +=
|
216
|
"<datapackage id=\"" + questionId + "\">"
|
217
|
+ "<entity id=\"" + questionId + "\">"
|
218
|
+ "<attribute index=\"0\">"
|
219
|
+ "<pathexpr label=\"qId\">//assessment/section/item/@ident</pathexpr>"
|
220
|
+ "</attribute>"
|
221
|
+ "<attribute index=\"1\">"
|
222
|
+ "<pathexpr label=\"qTitle\">//assessment/section/item/@title</pathexpr>"
|
223
|
+ "</attribute>"
|
224
|
+ "<attribute index=\"2\">"
|
225
|
+ "<pathexpr label=\"qLabel\">//assessment/section/item/presentation/@label</pathexpr>"
|
226
|
+ "</attribute>"
|
227
|
+ "</entity>"
|
228
|
+ "</datapackage>";
|
229
|
}
|
230
|
|
231
|
tempQuery += "</selection>";
|
232
|
|
233
|
//join to the quesion "table"
|
234
|
if (questionId.length > 0) {
|
235
|
tempQuery +=
|
236
|
"<where>"
|
237
|
+ "<condition type=\"join\">"
|
238
|
+ "<left>"
|
239
|
+ "<datapackage id=\"" + docId + "\">"
|
240
|
+ "<entity index=\"0\">"
|
241
|
+ "<attribute index=\"1\"/>"
|
242
|
+ "</entity>"
|
243
|
+ "</datapackage>"
|
244
|
+ "</left>"
|
245
|
+ "<operator>=</operator>"
|
246
|
+ "<right>"
|
247
|
+ "<datapackage id=\"" + questionId + "\">"
|
248
|
+ "<entity id=\"" + questionId + "\">"
|
249
|
+ "<attribute index=\"0\">"
|
250
|
+ "<pathexpr label=\"qId\">//assessment/section/item/@ident</pathexpr>"
|
251
|
+ "</attribute>"
|
252
|
+ "</entity>"
|
253
|
+ "</datapackage>"
|
254
|
+ "</right>"
|
255
|
+ "</condition>"
|
256
|
+ "</where>";
|
257
|
}
|
258
|
|
259
|
tempQuery += "</query>";
|
260
|
|
261
|
} // for questionId loop
|
262
|
|
263
|
|
264
|
} //for docObjs loop
|
265
|
|
266
|
tempQuery +=
|
267
|
"</union>"
|
268
|
+ "</dataquery>";
|
269
|
|
270
|
alert(tempQuery);
|
271
|
|
272
|
return tempQuery;
|
273
|
}
|
274
|
|
275
|
function generateSearchString(searchString, searchAssessments, searchAssessmentItems) {
|
276
|
var queryString =
|
277
|
"<pathquery version=\"1.2\">"
|
278
|
+"<querytitle>Web-Search</querytitle>";
|
279
|
|
280
|
/** assessments **/
|
281
|
if (searchAssessments) {
|
282
|
|
283
|
queryString +=
|
284
|
"<returndoctype>edml://ecoinformatics.org/edml</returndoctype>"
|
285
|
|
286
|
//assessment fields
|
287
|
+"<returnfield>assessment/duration</returnfield>"
|
288
|
+"<returnfield>assessment/@title</returnfield>"
|
289
|
+"<returnfield>assessment/@id</returnfield>"
|
290
|
+"<returnfield>lom/general/title/string</returnfield>"
|
291
|
+"<returnfield>lom/general/keyword/string</returnfield>"
|
292
|
+"<returnfield>individualName/surName</returnfield>"
|
293
|
+"<returnfield>organizationName</returnfield>"
|
294
|
|
295
|
+"<returnfield>assessmentItems/assessmentItem/assessmentItemId</returnfield>";
|
296
|
|
297
|
}
|
298
|
|
299
|
/** questions **/
|
300
|
if (searchAssessmentItems) {
|
301
|
queryString +=
|
302
|
"<returndoctype>http://www.imsglobal.org/xsd/ims_qtiasiv1p2</returndoctype>"
|
303
|
|
304
|
//question (qti) fields
|
305
|
+"<returnfield>item/@title</returnfield>"
|
306
|
+"<returnfield>item/@ident</returnfield>"
|
307
|
+"<returnfield>qtimetadata/qtimetadatafield/fieldlabel</returnfield>"
|
308
|
+"<returnfield>qtimetadata/qtimetadatafield/fieldentry</returnfield>"
|
309
|
//classification
|
310
|
+"<returnfield>fieldlabel</returnfield>"
|
311
|
+"<returnfield>fieldentry</returnfield>"
|
312
|
+"<returnfield>objectives/material/mattext</returnfield>"
|
313
|
//question content
|
314
|
+"<returnfield>presentation/flow/material/mattext</returnfield>"
|
315
|
+"<returnfield>response_label/@ident</returnfield>"
|
316
|
+"<returnfield>response_label/material/mattext</returnfield>";
|
317
|
}
|
318
|
|
319
|
queryString +=
|
320
|
"<querygroup operator=\"UNION\">"
|
321
|
+"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
|
322
|
+"<value>" + searchString + "</value>"
|
323
|
+"</queryterm>"
|
324
|
+"</querygroup>"
|
325
|
+"</pathquery>";
|
326
|
|
327
|
return queryString;
|
328
|
|
329
|
}
|
330
|
|
331
|
|
332
|
function generateAssessmentSearchString(assessmentItemId) {
|
333
|
var query =
|
334
|
"<pathquery version='1.2'>"
|
335
|
+"<querytitle>Containing-Assessment-Search</querytitle>"
|
336
|
|
337
|
+"<returndoctype>edml://ecoinformatics.org/edml</returndoctype>"
|
338
|
|
339
|
+"<returnfield>assessment/@title</returnfield>"
|
340
|
+"<returnfield>assessment/@id</returnfield>"
|
341
|
+"<returnfield>assessment/duration</returnfield>"
|
342
|
+"<returnfield>lom/general/title/string</returnfield>"
|
343
|
+"<returnfield>lom/general/keyword/string</returnfield>"
|
344
|
+"<returnfield>individualName/surName</returnfield>"
|
345
|
+"<returnfield>organizationName</returnfield>"
|
346
|
|
347
|
+"<returnfield>assessmentItems/assessmentItem/assessmentItemId</returnfield>";
|
348
|
|
349
|
if (assessmentItemId.length > 0) {
|
350
|
query += "<querygroup operator='UNION'>";
|
351
|
|
352
|
//add the assessmentId if included
|
353
|
query +=
|
354
|
"<queryterm searchmode='contains' casesensitive='false'>"
|
355
|
+"<value>"
|
356
|
+ assessmentItemId
|
357
|
+"</value>"
|
358
|
+"<pathexpr>assessmentItemId</pathexpr>"
|
359
|
+"</queryterm>";
|
360
|
|
361
|
//close the query group
|
362
|
query +=
|
363
|
"</querygroup>";
|
364
|
}
|
365
|
|
366
|
query += "</pathquery>";
|
367
|
|
368
|
return query;
|
369
|
}
|
370
|
|
371
|
function callAjax(metacatURL, myQuery, qfmt) {
|
372
|
|
373
|
//alert("calling ajax: " + metacatURL);
|
374
|
//alert("myQuery: " + myQuery);
|
375
|
|
376
|
//var myRequest = new Ajax.Request(
|
377
|
var myUpdate = new Ajax.Updater(
|
378
|
'ajaxResults',
|
379
|
metacatURL,
|
380
|
{ method: 'post',
|
381
|
parameters: { action: 'squery', qformat: qfmt, query: myQuery},
|
382
|
evalScripts: true,
|
383
|
//onSuccess: function(transport) {alert('success: ' + transport.status);},
|
384
|
onFailure: function(transport) {alert('failure making ajax call');}
|
385
|
});
|
386
|
|
387
|
//alert("done calling ajax");
|
388
|
}
|