Project

General

Profile

1
function checkSearch(submitFormObj) {
2
	//alert("calling method");
3
	
4
    //var checkBox = document.getElementById("searchAll");
5
	var docId = submitFormObj.docid.value;
6
	//alert("docId=" + docId);
7
	
8
	//do we want question metadata?
9
	var includeQuestions = submitFormObj.includeQuestionsRadio.checked;
10
	var questionIds = new Array();
11
	questionIds[0] = "";
12
	
13
	if (includeQuestions) {
14
		if (submitFormObj.assessmentItemId.length > 1) {
15
			for (var i=0; i < submitFormObj.assessmentItemId.length; i++) {
16
				questionIds[i] = submitFormObj.assessmentItemId[i].value;
17
			}
18
		}
19
		else {
20
			questionIds[0] = submitFormObj.assessmentItemId.value;
21
		}
22
	}
23
	
24
	//alert("questionIds=" + questionIds);
25
	
26
	//construct the assessment metadata query
27
	var metadataAttributes = "";
28
	var index = 0;
29
	for (var i=0; i < submitFormObj.length; i++) {
30
		var formElement = submitFormObj.elements[i];
31
		if (formElement.type == "checkbox" && formElement.checked) {
32
		
33
			metadataAttributes += "<attribute index=\"";
34
			metadataAttributes += index;
35
			metadataAttributes += "\">";
36
			
37
			metadataAttributes += "<pathexpr label=\"";
38
			metadataAttributes += formElement.name;
39
			metadataAttributes += "\">";
40
			metadataAttributes += formElement.value;
41
			metadataAttributes += "</pathexpr>";
42
			
43
			metadataAttributes += "</attribute>";
44
			
45
			index++;
46
		}
47
	}
48
	
49
	//assemble the assessment metadata
50
	metadataAttributes = 
51
				"<datapackage id=\"" + docId + "\">"
52
					+ "<entity id=\"" + docId + "\">"
53
						+ metadataAttributes
54
					+ "</entity>"
55
				+ "</datapackage>";
56
	
57
	//construct the entire query
58
	var tempQuery = 
59
        "<?xml version=\"1.0\"?>"
60
        + "<dataquery>"
61
			+ "<union>";
62
			
63
			//loop for each question item
64
			for (var i=0; i < questionIds.length; i++) {
65
				var questionId = questionIds[i];
66
				
67
				tempQuery +=
68
					"<query>"
69
					//select the data
70
					+ "<selection>"
71
						+ "<datapackage id=\"" + docId + "\">"
72
							+ "<entity index=\"0\">"
73
								+ "<attribute index=\"0\"/>"
74
								+ "<attribute index=\"1\"/>"
75
								//omit student id attribute
76
								+ "<attribute index=\"3\"/>"
77
								+ "<attribute index=\"4\"/>"
78
							+ "</entity>"
79
						+ "</datapackage>";
80
						
81
						//select the metadata
82
						tempQuery += metadataAttributes;
83

    
84
						//select the question metadata						
85
						if (questionId.length > 0) {
86
							tempQuery +=
87
							"<datapackage id=\"" + questionId + "\">"
88
								+ "<entity id=\"" + questionId + "\">"
89
									+ "<attribute index=\"0\">"
90
										+ "<pathexpr label=\"qId\">//assessment/section/item/@ident</pathexpr>"
91
									+ "</attribute>"
92
									+ "<attribute index=\"1\">"
93
										+ "<pathexpr label=\"qTitle\">//assessment/section/item/@title</pathexpr>"
94
									+ "</attribute>"
95
									+ "<attribute index=\"2\">"
96
										+ "<pathexpr label=\"qLabel\">//assessment/section/item/presentation/@label</pathexpr>"
97
									+ "</attribute>"
98
								+ "</entity>"
99
							+ "</datapackage>";
100
						}
101
						
102
					tempQuery += "</selection>";
103
					
104
					//join to the quesion "table"
105
					if (questionId.length > 0) {
106
						tempQuery +=
107
							"<where>"
108
								+ "<condition type=\"join\">"
109
									+ "<left>"
110
										+ "<datapackage id=\"" + docId + "\">"
111
											+ "<entity index=\"0\">"
112
												+ "<attribute index=\"1\"/>"
113
											+ "</entity>"
114
										+ "</datapackage>"
115
									+ "</left>"
116
									+ "<operator>=</operator>"
117
									+ "<right>"
118
										+ "<datapackage id=\"" + questionId + "\">"
119
											+ "<entity id=\"" + questionId + "\">"
120
												+ "<attribute index=\"0\">"
121
													+ "<pathexpr label=\"qId\">//assessment/section/item/@ident</pathexpr>"
122
												+ "</attribute>"
123
											+ "</entity>"
124
										+ "</datapackage>"
125
									+ "</right>"
126
								+ "</condition>"
127
							+ "</where>";
128
					}
129
					
130
					tempQuery += "</query>";
131
				}
132
				 
133
			tempQuery +=
134
			 "</union>"	
135
        + "</dataquery>";
136
         
137
         submitFormObj.dataquery.value = tempQuery;
138
         
139
         //alert(submitFormObj.dataquery.value);
140
         
141
    return true;
142
}
(11-11/11)