001: /**********************************************************************************
002: *
003: * $Id: OverviewBean.java 20001 2006-12-22 19:41:33Z ray@media.berkeley.edu $
004: *
005: ***********************************************************************************
006: *
007: * Copyright (c) 2005 The Regents of the University of California, The MIT Corporation
008: *
009: * Licensed under the Educational Community License, Version 1.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.opensource.org/licenses/ecl1.php
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: *
021: **********************************************************************************/package org.sakaiproject.tool.gradebook.ui;
022:
023: import java.io.Serializable;
024: import java.util.HashMap;
025: import java.util.Iterator;
026: import java.util.List;
027: import java.util.Map;
028:
029: import org.apache.commons.logging.Log;
030: import org.apache.commons.logging.LogFactory;
031: import org.sakaiproject.tool.gradebook.Assignment;
032: import org.sakaiproject.tool.gradebook.GradableObject;
033: import org.sakaiproject.tool.gradebook.Gradebook;
034: import org.sakaiproject.tool.gradebook.jsf.FacesUtil;
035:
036: /**
037: * Backing bean for the visible list of assignments in the gradebook.
038: */
039: public class OverviewBean extends GradebookDependentBean implements
040: Serializable {
041: private static final Log logger = LogFactory
042: .getLog(OverviewBean.class);
043:
044: private static final Map columnSortMap;
045:
046: private List gradableObjects;
047: private double totalPoints;
048:
049: static {
050: columnSortMap = new HashMap();
051: columnSortMap.put(Assignment.SORT_BY_NAME,
052: Assignment.nameComparator);
053: columnSortMap.put(Assignment.SORT_BY_DATE,
054: Assignment.dateComparator);
055: columnSortMap.put(Assignment.SORT_BY_RELEASED,
056: Assignment.releasedComparator);
057: columnSortMap.put(Assignment.SORT_BY_MEAN,
058: Assignment.meanComparator);
059: columnSortMap.put(Assignment.SORT_BY_POINTS,
060: Assignment.pointsComparator);
061:
062: }
063:
064: public List getGradableObjects() {
065: return gradableObjects;
066: }
067:
068: public void setGradableObjects(List gradableObjects) {
069: this .gradableObjects = gradableObjects;
070: }
071:
072: protected void init() {
073: // Get the list of assignments for this gradebook, sorted as defined in the overview page.
074: gradableObjects = getGradebookManager()
075: .getAssignmentsAndCourseGradeWithStats(
076: getGradebookId(), getAssignmentSortColumn(),
077: isAssignmentSortAscending());
078:
079: totalPoints = 0;
080: for (Iterator iter = gradableObjects.iterator(); iter.hasNext();) {
081: GradableObject go = (GradableObject) iter.next();
082: if (go.isCourseGrade()) {
083: continue;
084: }
085: Assignment asn = (Assignment) go;
086: if (asn.isNotCounted()) {
087: continue;
088: }
089: totalPoints += asn.getPointsPossible().doubleValue();
090: }
091: }
092:
093: // Delegated sort methods
094: public String getAssignmentSortColumn() {
095: return getPreferencesBean().getAssignmentSortColumn();
096: }
097:
098: public void setAssignmentSortColumn(String assignmentSortColumn) {
099: getPreferencesBean().setAssignmentSortColumn(
100: assignmentSortColumn);
101: }
102:
103: public boolean isAssignmentSortAscending() {
104: return getPreferencesBean().isAssignmentSortAscending();
105: }
106:
107: public void setAssignmentSortAscending(boolean sortAscending) {
108: getPreferencesBean().setAssignmentSortAscending(sortAscending);
109: }
110:
111: /**
112: * @return The comma-separated list of css styles to use in displaying the rows
113: */
114: public String getRowStyles() {
115: StringBuffer sb = new StringBuffer();
116: for (Iterator iter = gradableObjects.iterator(); iter.hasNext();) {
117: GradableObject go = (GradableObject) iter.next();
118: if (go.isCourseGrade()) {
119: sb.append("internal");
120: break;
121: } else {
122: Assignment asn = (Assignment) go;
123: if (asn.isExternallyMaintained()) {
124: sb.append("external,");
125: } else {
126: sb.append("internal,");
127: }
128: }
129: }
130: return sb.toString();
131: }
132:
133: public String getGradeOptionSummary() {
134: String gradeOptionSummary;
135: Gradebook gradebook = getGradebook();
136: String gradeMappingName = gradebook.getSelectedGradeMapping()
137: .getName();
138: if (gradebook.isAssignmentsDisplayed()) {
139: if (gradebook.isCourseGradeDisplayed()) {
140: gradeOptionSummary = FacesUtil.getLocalizedString(
141: "overview_grade_option_all_viewable",
142: new String[] { gradeMappingName });
143: } else {
144: gradeOptionSummary = FacesUtil
145: .getLocalizedString("overview_grade_option_assignments_viewable");
146: }
147: } else if (gradebook.isCourseGradeDisplayed()) {
148: gradeOptionSummary = FacesUtil.getLocalizedString(
149: "overview_grade_option_course_grade_viewable",
150: new String[] { gradeMappingName });
151: } else {
152: gradeOptionSummary = FacesUtil
153: .getLocalizedString("overview_grade_option_none_viewable");
154: }
155: return gradeOptionSummary;
156: }
157:
158: public Double getTotalPoints() {
159: return new Double(totalPoints);
160: }
161:
162: }
|