Project

General

Profile

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
/**
276
*	@param searchTerms - and object (hashtable) with, pay attention now:
277
	keys are search values
278
*   values are pathexprs
279
**/
280
function generateSearchString(searchTerms, operator, searchAssessments, searchAssessmentItems) {
281
	var queryString = 
282
		"<pathquery version=\"1.2\">"
283
			+"<querytitle>Web-Search</querytitle>";
284
		
285
	/** assessments **/
286
	if (searchAssessments) {
287
	
288
		queryString +=
289
			"<returndoctype>edml://ecoinformatics.org/edml</returndoctype>"
290
			
291
			//assessment fields
292
               +"<returnfield>assessment/duration</returnfield>"
293
               +"<returnfield>assessment/@title</returnfield>"
294
               +"<returnfield>assessment/@id</returnfield>"
295
               +"<returnfield>lom/general/title/string</returnfield>"
296
               +"<returnfield>lom/general/keyword/string</returnfield>"
297
               +"<returnfield>individualName/surName</returnfield>"
298
               +"<returnfield>organizationName</returnfield>"
299
               
300
               +"<returnfield>assessmentItems/assessmentItem/assessmentItemId</returnfield>";
301
               
302
	}
303
						
304
	/** questions **/
305
	if (searchAssessmentItems) {
306
		queryString +=
307
			"<returndoctype>http://www.imsglobal.org/xsd/ims_qtiasiv1p2</returndoctype>"
308
			
309
			//question (qti) fields
310
			+"<returnfield>item/@title</returnfield>"
311
			+"<returnfield>item/@ident</returnfield>"
312
               +"<returnfield>qtimetadata/qtimetadatafield/fieldlabel</returnfield>"
313
               +"<returnfield>qtimetadata/qtimetadatafield/fieldentry</returnfield>"
314
			//classification
315
			+"<returnfield>fieldlabel</returnfield>"
316
			+"<returnfield>fieldentry</returnfield>"
317
			+"<returnfield>objectives/material/mattext</returnfield>"
318
			//question content
319
			+"<returnfield>presentation/flow/material/mattext</returnfield>"
320
			+"<returnfield>response_label/@ident</returnfield>"
321
			+"<returnfield>response_label/material/mattext</returnfield>";
322
	}		
323
    
324
    queryString +=
325
    	"<querygroup operator=\"" + operator + "\">";
326
                         
327
    for (var i in searchTerms) {
328
    	var key = i;
329
    	var value = searchTerms[i];                        
330
		queryString +=
331
			"<queryterm searchmode=\"contains\" casesensitive=\"false\">";
332
			if (key != "anyValue") {
333
				queryString += "<pathexpr>" + key + "</pathexpr>";
334
			}	
335
	      	queryString += "<value>" + value + "</value>";
336
	    queryString +="</queryterm>";
337
    }
338
    
339
	queryString +=
340
		"</querygroup>"
341
	+"</pathquery>";
342
	
343
	return queryString;
344
				
345
}
346

    
347

    
348
function generateAssessmentSearchString(assessmentItemId) {
349
	var query = 
350
		"<pathquery version='1.2'>"
351
		     +"<querytitle>Containing-Assessment-Search</querytitle>"
352
		     
353
		     +"<returndoctype>edml://ecoinformatics.org/edml</returndoctype>"
354
		                           
355
                      +"<returnfield>assessment/@title</returnfield>"
356
                      +"<returnfield>assessment/@id</returnfield>"
357
                      +"<returnfield>assessment/duration</returnfield>"
358
                      +"<returnfield>lom/general/title/string</returnfield>"
359
                      +"<returnfield>lom/general/keyword/string</returnfield>"
360
                      +"<returnfield>individualName/surName</returnfield>"
361
                      +"<returnfield>organizationName</returnfield>"
362
                      
363
                      +"<returnfield>assessmentItems/assessmentItem/assessmentItemId</returnfield>";
364
                      
365
		    if (assessmentItemId.length > 0) {
366
			    query += "<querygroup operator='UNION'>";
367
			    
368
			    //add the assessmentId if included
369
			    query +=
370
			     		"<queryterm searchmode='contains' casesensitive='false'>"
371
			                  +"<value>"
372
			                  + assessmentItemId
373
			                  +"</value>"
374
			                  +"<pathexpr>assessmentItemId</pathexpr>"
375
			          +"</queryterm>";
376
				
377
			    //close the query group      
378
			     query +=
379
			     "</querygroup>";
380
			}
381
			     
382
		query += "</pathquery>";
383
		
384
	return query;	
385
}
386

    
387
function generateAssessmentListString(assessmentIds) {
388
	var query = 
389
		"<pathquery version='1.2'>"
390
		     +"<querytitle>Assessment-List</querytitle>"
391
		     
392
		     +"<returndoctype>edml://ecoinformatics.org/edml</returndoctype>"
393
		                           
394
                      +"<returnfield>assessment/@title</returnfield>"
395
                      +"<returnfield>assessment/@id</returnfield>"
396
                      +"<returnfield>assessment/duration</returnfield>"
397
                      +"<returnfield>lom/general/title/string</returnfield>"
398
                      +"<returnfield>lom/general/keyword/string</returnfield>"
399
                      +"<returnfield>individualName/surName</returnfield>"
400
                      +"<returnfield>organizationName</returnfield>"
401
                      
402
                      +"<returnfield>assessmentItems/assessmentItem/assessmentItemId</returnfield>";
403
                      
404
		    if (assessmentIds.length > 0) {
405
			    query += "<querygroup operator='UNION'>";
406
			    
407
			    //add the assessmentId if included
408
			    for (var i=0; i < assessmentIds.length; i++) {
409
				    query +=
410
				     		"<queryterm searchmode='equals' casesensitive='false'>"
411
				                  +"<value>"
412
				                  + assessmentIds[i]
413
				                  +"</value>"
414
				                  +"<pathexpr>@packageId</pathexpr>"
415
				          +"</queryterm>";
416
				}
417
			    //close the query group      
418
			     query +=
419
			     "</querygroup>";
420
			}
421
			     
422
		query += "</pathquery>";
423
		
424
	return query;	
425
}
426

    
427
function callAjax(metacatURL, myQuery, qfmt) {
428
														
429
	//alert("calling ajax: " + metacatURL);
430
	//alert("myQuery: " + myQuery);
431
	
432
	//var myRequest = new Ajax.Request(
433
	var myUpdate = new Ajax.Updater(
434
		'ajaxResults',
435
		metacatURL,
436
		{	method: 'post',
437
			parameters: { action: 'squery', qformat: qfmt, query: myQuery},
438
			evalScripts: true, 
439
			//onSuccess: function(transport) {alert('success: ' + transport.status);},
440
			onFailure: function(transport) {alert('failure making ajax call');}
441
		 });
442
		 
443
	 //alert("done calling ajax");
444
}
(13-13/13)