01: /**********************************************************************************
02: *
03: * $Id: CourseGradesToSpreadsheetConverterDefault.java 22061 2007-03-01 22:54:37Z ray@media.berkeley.edu $
04: *
05: ***********************************************************************************
06: *
07: * Copyright (c) 2007 The Regents of the University of California
08: *
09: * Licensed under the Educational Community License, Version 1.0 (the "License");
10: * you may not use this file except in compliance with the License.
11: * You may obtain a copy of the License at
12: *
13: * http://www.opensource.org/licenses/ecl1.php
14: *
15: * Unless required by applicable law or agreed to in writing, software
16: * distributed under the License is distributed on an "AS IS" BASIS,
17: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18: * See the License for the specific language governing permissions and
19: * limitations under the License.
20: *
21: **********************************************************************************/package org.sakaiproject.tool.gradebook.ui;
22:
23: import java.util.ArrayList;
24: import java.util.List;
25: import java.util.Map;
26:
27: import org.sakaiproject.section.api.coursemanagement.EnrollmentRecord;
28: import org.sakaiproject.section.api.coursemanagement.User;
29: import org.sakaiproject.tool.gradebook.CourseGrade;
30: import org.sakaiproject.tool.gradebook.CourseGradeRecord;
31: import org.sakaiproject.tool.gradebook.CourseGradesToSpreadsheetConverter;
32: import org.sakaiproject.tool.gradebook.jsf.FacesUtil;
33:
34: /**
35: *
36: */
37: public class CourseGradesToSpreadsheetConverterDefault implements
38: CourseGradesToSpreadsheetConverter {
39:
40: /* (non-Javadoc)
41: * @see org.sakaiproject.tool.gradebook.CourseGradesConverter#getSpreadsheetData(java.util.List, org.sakaiproject.tool.gradebook.CourseGrade, java.util.Map)
42: */
43: public List<List<Object>> getSpreadsheetData(
44: List<EnrollmentRecord> enrollments,
45: CourseGrade courseGrade,
46: Map<String, CourseGradeRecord> gradesMap) {
47: List<List<Object>> spreadsheetData = new ArrayList<List<Object>>();
48:
49: // Build column headers.
50: List<Object> headerRow = new ArrayList<Object>();
51: headerRow
52: .add(FacesUtil.getLocalizedString("export_student_id"));
53: headerRow.add(FacesUtil
54: .getLocalizedString("export_student_name"));
55: headerRow
56: .add(FacesUtil
57: .getLocalizedString("course_grade_details_course_grade_column_name"));
58: spreadsheetData.add(headerRow);
59:
60: // Build student grade rows.
61: for (Object enrollment : enrollments) {
62: User student = ((EnrollmentRecord) enrollment).getUser();
63: String studentUid = student.getUserUid();
64: Map studentMap = (Map) gradesMap.get(studentUid);
65: List<Object> row = new ArrayList<Object>();
66: row.add(student.getDisplayId());
67: row.add(student.getSortName());
68: String grade = null;
69: if (studentMap != null) {
70: CourseGradeRecord gradeRecord = (CourseGradeRecord) studentMap
71: .get(courseGrade.getId());
72: if (gradeRecord != null) {
73: grade = gradeRecord.getDisplayGrade();
74: }
75: }
76: row.add(grade);
77: spreadsheetData.add(row);
78: }
79:
80: return spreadsheetData;
81: }
82:
83: }
|