Example #1
0
  /** @see org.sakaiproject.tool.gradebook.ui.InitializableBean#init() */
  public void init() {
    previousStudent = null;
    nextStudent = null;
    studentSections = null;

    String sortByCol = getSortColumn();
    boolean sortAsc = isSortAscending();

    setIsInstructorView(true);

    if (getStudentUid() != null) {
      super.init();

      studentEmailAddress = getUserDirectoryService().getUserEmailAddress(getStudentUid());
      studentSections = getStudentSectionsForDisplay();

      // set up the "next" and "previous" student navigation
      // TODO preserve filter/sort status from originating page
      if (orderedEnrollmentList == null) {
        orderedEnrollmentList = new ArrayList();
        if (returnToPage.equals(ROSTER_PAGE)) {
          super.setSelectedSectionFilterValue(getPreferencesBean().getRosterTableSectionFilter());
          maxDisplayedScoreRows = 0;
          orderedEnrollmentList = getOrderedEnrolleesFromRosterPage();
        } else if (returnToPage.equals(ASSIGN_DETAILS_PAGE)) {
          super.setSelectedSectionFilterValue(
              getPreferencesBean().getAssignmentDetailsTableSectionFilter());
          maxDisplayedScoreRows = 0;
          orderedEnrollmentList = getOrderedEnrolleesFromAssignDetailsPage();
        }
      }

      if (orderedEnrollmentList != null && orderedEnrollmentList.size() > 1) {
        int index = 0;
        while (index < orderedEnrollmentList.size()) {
          EnrollmentRecord enrollee = (EnrollmentRecord) orderedEnrollmentList.get(index);
          if (enrollee.getUser().getUserUid().equals(getStudentUid())) {
            currentStudent = enrollee;
            if (index - 1 >= 0) {
              previousStudent = (EnrollmentRecord) orderedEnrollmentList.get(index - 1);
            }
            if (index + 1 < orderedEnrollmentList.size()) {
              nextStudent = (EnrollmentRecord) orderedEnrollmentList.get(index + 1);
            }
            break;
          }
          index++;
        }
      }

      setSortColumn(sortByCol);
      setSortAscending(sortAsc);
    }
  }
  /**
   * @param enrollmentList - list of EnrollmentRecords
   * @return Ordered Map of student Id to EnrollmentRecord
   */
  private Map transformToOrderedEnrollmentMap(List enrollmentList) {
    Map enrollmentMap;

    if (isEnrollmentSort()) {
      Collections.sort(enrollmentList, (Comparator) columnSortMap.get(getSortColumn()));
      enrollmentList = finalizeSortingAndPaging(enrollmentList);
      enrollmentMap = new LinkedHashMap(); // Preserve ordering
    } else {
      enrollmentMap = new HashMap();
    }

    for (Iterator iter = enrollmentList.iterator(); iter.hasNext(); ) {
      EnrollmentRecord enr = (EnrollmentRecord) iter.next();
      enrollmentMap.put(enr.getUser().getUserUid(), enr);
    }

    return enrollmentMap;
  }
Example #3
0
  /**
   * If we came to the instructor view from the roster page, we need to set the previous and next
   * student info according to the order and filter on the roster page
   *
   * @return
   */
  private List getOrderedEnrolleesFromRosterPage() {
    // it may be sorted by name, id, cumulative score, or any of the individual
    // assignments
    setSortColumn(getPreferencesBean().getRosterTableSortColumn());
    setSortAscending(getPreferencesBean().isRosterTableSortAscending());

    Map enrollmentMap = getOrderedEnrollmentMapForAllItems();

    List workingEnrollments = new ArrayList(enrollmentMap.keySet());

    if (isEnrollmentSort()) {
      return workingEnrollments;
    }

    Map studentIdItemIdFunctionMap = new HashMap();
    Map studentIdEnrRecMap = new HashMap();
    for (Iterator enrIter = workingEnrollments.iterator(); enrIter.hasNext(); ) {
      EnrollmentRecord enr = (EnrollmentRecord) enrIter.next();
      if (enr != null) {
        String studentId = enr.getUser().getUserUid();
        Map itemFunctionMap = (Map) enrollmentMap.get(enr);

        studentIdItemIdFunctionMap.put(studentId, itemFunctionMap);
        studentIdEnrRecMap.put(studentId, enr);
      }
    }

    List rosterGradeRecords =
        getGradebookManager()
            .getAllAssignmentGradeRecords(getGradebookId(), studentIdItemIdFunctionMap.keySet());
    Map gradeRecordMap = new HashMap();

    if (!isUserAbleToGradeAll() && isUserHasGraderPermissions()) {
      getGradebookManager()
          .addToGradeRecordMap(gradeRecordMap, rosterGradeRecords, studentIdItemIdFunctionMap);
      // we need to re-sort these records b/c some may actually be null based upon permissions.
      // retrieve updated grade recs from gradeRecordMap
      List updatedGradeRecs = new ArrayList();
      for (Iterator<Map.Entry<String, Map>> iter = gradeRecordMap.entrySet().iterator();
          iter.hasNext(); ) {
        Map.Entry<String, Map> entry = iter.next();
        String studentId = entry.getKey();
        Map itemIdGradeRecMap = (Map) gradeRecordMap.get(studentId);
        if (!itemIdGradeRecMap.isEmpty()) {
          updatedGradeRecs.addAll(itemIdGradeRecMap.values());
        }
      }
      Collections.sort(updatedGradeRecs, AssignmentGradeRecord.calcComparator);
      rosterGradeRecords = updatedGradeRecs;
    } else {
      getGradebookManager().addToGradeRecordMap(gradeRecordMap, rosterGradeRecords);
    }
    if (logger.isDebugEnabled())
      logger.debug("init - gradeRecordMap.keySet().size() = " + gradeRecordMap.keySet().size());

    List assignments = null;
    String selectedCategoryUid = getSelectedCategoryUid();
    CourseGrade courseGrade = getGradebookManager().getCourseGrade(getGradebookId());
    if (selectedCategoryUid == null) {
      assignments = getGradebookManager().getAssignments(getGradebookId());
    } else {
      assignments =
          getGradebookManager()
              .getAssignmentsForCategory(new Long(getSelectedSectionFilterValue().longValue()));
    }

    List courseGradeRecords =
        getGradebookManager()
            .getPointsEarnedCourseGradeRecords(
                courseGrade, studentIdItemIdFunctionMap.keySet(), assignments, gradeRecordMap);
    Collections.sort(courseGradeRecords, CourseGradeRecord.calcComparator);
    getGradebookManager().addToGradeRecordMap(gradeRecordMap, courseGradeRecords);
    rosterGradeRecords.addAll(courseGradeRecords);

    // do category results
    Map categoryResultMap = new HashMap();
    List categories = getGradebookManager().getCategories(getGradebookId());
    getGradebookManager()
        .addToCategoryResultMap(categoryResultMap, categories, gradeRecordMap, studentIdEnrRecMap);
    if (logger.isDebugEnabled())
      logger.debug(
          "init - categoryResultMap.keySet().size() = " + categoryResultMap.keySet().size());

    // Need to sort and page based on a scores column.
    String sortColumn = getSortColumn();
    List scoreSortedEnrollments = new ArrayList();
    for (Iterator iter = rosterGradeRecords.iterator(); iter.hasNext(); ) {
      AbstractGradeRecord agr = (AbstractGradeRecord) iter.next();
      if (getColumnHeader(agr.getGradableObject()).equals(sortColumn)) {
        scoreSortedEnrollments.add(studentIdEnrRecMap.get(agr.getStudentId()));
      }
    }

    // Put enrollments with no scores at the beginning of the final list.
    workingEnrollments.removeAll(scoreSortedEnrollments);

    // Add all sorted enrollments with scores into the final list
    workingEnrollments.addAll(scoreSortedEnrollments);

    workingEnrollments = finalizeSortingAndPaging(workingEnrollments);

    return workingEnrollments;
  }
 public int compare(EnrollmentRecord o1, EnrollmentRecord o2) {
   long user1DisplayId = Long.parseLong(o1.getUser().getDisplayId());
   long user2DisplayId = Long.parseLong(o2.getUser().getDisplayId());
   return (int) (user1DisplayId - user2DisplayId);
 }
 public int compare(EnrollmentRecord o1, EnrollmentRecord o2) {
   return o1.getUser().getDisplayId().compareToIgnoreCase(o2.getUser().getDisplayId());
 }
 public int compare(EnrollmentRecord o1, EnrollmentRecord o2) {
   return Collator.getInstance()
       .compare(o1.getUser().getSortName(), o2.getUser().getSortName());
 }