001: /**********************************************************************************
002: *
003: * $Id: TestGradebookTool.java 18134 2006-11-14 18:59:25Z jholtzman@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.util.HashSet;
024: import java.util.Iterator;
025: import java.util.List;
026: import java.util.Set;
027:
028: import javax.faces.context.FacesContext;
029: import javax.faces.event.ActionEvent;
030:
031: import org.sakaiproject.section.api.SectionAwareness;
032: import org.sakaiproject.section.api.coursemanagement.EnrollmentRecord;
033: import org.sakaiproject.section.api.facade.Role;
034: import org.sakaiproject.tool.gradebook.Assignment;
035: import org.sakaiproject.tool.gradebook.Gradebook;
036: import org.sakaiproject.tool.gradebook.business.GradebookManager;
037:
038: /**
039: * @author josh
040: *
041: */
042: public class TestGradebookTool {
043: // UI State
044: Gradebook selectedGradebook;
045:
046: // Services
047: private GradebookManager gradebookManager;
048: private SectionAwareness sectionAwareness;
049:
050: /**
051: * @return A List of all assignments in the currently selected gradebook
052: */
053: public List getAssignments() {
054: List gradableObjects = gradebookManager
055: .getAssignmentsAndCourseGradeWithStats(
056: selectedGradebook.getId(),
057: Assignment.DEFAULT_SORT, true);
058: return gradableObjects;
059: }
060:
061: /**
062: * @return A Set of all Users enrolled in the currently selected gradebook
063: */
064: public Set getStudents() {
065: Set students = new HashSet();
066: List enrollments = sectionAwareness.getSiteMembersInRole(
067: selectedGradebook.getUid(), Role.STUDENT);
068: for (Iterator enrIter = enrollments.iterator(); enrIter
069: .hasNext();) {
070: students.add(((EnrollmentRecord) enrIter.next()).getUser());
071: }
072: return students;
073: }
074:
075: //// JSF Action Events ////
076: public void selectGradebook(ActionEvent ae) {
077: selectedGradebook = (Gradebook) FacesContext
078: .getCurrentInstance().getExternalContext()
079: .getRequestMap().get("gb");
080: }
081:
082: //// Tool state getters and setters
083:
084: /**
085: * @return Returns the selectedGradebook.
086: */
087: public Gradebook getSelectedGradebook() {
088: return selectedGradebook;
089: }
090:
091: /**
092: * @param selectedGradebook The selectedGradebook to set.
093: */
094: public void setSelectedGradebook(Gradebook selectedGradebook) {
095: this .selectedGradebook = selectedGradebook;
096: }
097:
098: //// Service Dependencies ////
099:
100: public SectionAwareness getSectionAwareness() {
101: return sectionAwareness;
102: }
103:
104: public void setSectionAwareness(SectionAwareness sectionAwareness) {
105: this .sectionAwareness = sectionAwareness;
106: }
107:
108: /**
109: * @return Returns the gradebookManager.
110: */
111: public GradebookManager getGradebookManager() {
112: return gradebookManager;
113: }
114:
115: /**
116: * @param gradebookManager The gradebookManager to set.
117: */
118: public void setGradebookManager(GradebookManager gradebookManager) {
119: this.gradebookManager = gradebookManager;
120: }
121: }
|