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