Exemplo n.º 1
0
  /**
   * If we came to the instructor view from the assign details page, we need to set the previous and
   * next student info according to the order and filter on the assign details page
   *
   * @return
   */
  private List getOrderedEnrolleesFromAssignDetailsPage() {
    setSortColumn(getPreferencesBean().getAssignmentDetailsTableSortColumn());
    setSortAscending(getPreferencesBean().isAssignmentDetailsTableSortAscending());

    List assignGradeRecords = new ArrayList();
    List enrollments = new ArrayList();

    Long assignmentIdAsLong = getAssignmentIdAsLong();
    if (assignmentIdAsLong != null) {
      Assignment prevAssignment = getGradebookManager().getAssignment(assignmentIdAsLong);
      Category category = prevAssignment.getCategory();
      Long catId = null;
      if (category != null) catId = category.getId();

      Map enrollmentMap = getOrderedStudentIdEnrollmentMapForItem(catId);
      if (isEnrollmentSort()) {
        return new ArrayList(enrollmentMap.values());
      }

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

      if (getGradeEntryByPoints())
        assignGradeRecords =
            getGradebookManager().getAssignmentGradeRecords(prevAssignment, studentUids);
      else if (getGradeEntryByPercent() || getGradeEntryByLetter())
        assignGradeRecords =
            getGradebookManager().getAssignmentGradeRecordsConverted(prevAssignment, studentUids);

      // Need to sort and page based on a scores column.
      List scoreSortedStudentUids = new ArrayList();
      for (Iterator iter = assignGradeRecords.iterator(); iter.hasNext(); ) {
        AbstractGradeRecord agr = (AbstractGradeRecord) iter.next();
        scoreSortedStudentUids.add(agr.getStudentId());
      }

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

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

      studentUids = finalizeSortingAndPaging(studentUids);

      if (studentUids != null) {
        Iterator studentIter = studentUids.iterator();
        while (studentIter.hasNext()) {
          String studentId = (String) studentIter.next();
          EnrollmentRecord enrollee = (EnrollmentRecord) enrollmentMap.get(studentId);
          if (enrollee != null) enrollments.add(enrollee);
        }
      }
    }

    return enrollments;
  }
Exemplo n.º 2
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;
  }