Exemple #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;
  }
  protected void init() {
    graderIdToNameMap = new HashMap();

    defaultSearchString = getLocalizedString("search_default_student_search_string");
    if (searchString == null) {
      searchString = defaultSearchString;
    }

    // Section filtering.
    availableSections = getViewableSections();
    sectionFilterSelectItems = new ArrayList();

    // The first choice is always "All available enrollments"
    sectionFilterSelectItems.add(
        new SelectItem(
            new Integer(ALL_SECTIONS_SELECT_VALUE),
            FacesUtil.getLocalizedString("search_sections_all")));

    // TODO If there are unassigned students and the current user is allowed to see them, add them
    // next.

    // Add the available sections.
    for (int i = 0; i < availableSections.size(); i++) {
      CourseSection section = (CourseSection) availableSections.get(i);
      sectionFilterSelectItems.add(new SelectItem(new Integer(i), section.getTitle()));
    }

    // If the selected value now falls out of legal range due to sections
    // being deleted, throw it back to the default value (meaning everyone).
    int selectedSectionVal = selectedSectionFilterValue.intValue();
    if ((selectedSectionVal >= 0) && (selectedSectionVal >= availableSections.size())) {
      if (log.isInfoEnabled())
        log.info(
            "selectedSectionFilterValue="
                + selectedSectionFilterValue.intValue()
                + " but available sections="
                + availableSections.size());
      selectedSectionFilterValue = new Integer(ALL_SECTIONS_SELECT_VALUE);
    }

    // Category filtering
    availableCategories = getViewableCategories();
    categoryFilterSelectItems = new ArrayList();

    // The first choice is always "All Categories"
    categoryFilterSelectItems.add(
        new SelectItem(
            new Integer(ALL_CATEGORIES_SELECT_VALUE),
            FacesUtil.getLocalizedString("search_categories_all")));

    // Add available categories
    for (int i = 0; i < availableCategories.size(); i++) {
      Category cat = (Category) availableCategories.get(i);
      categoryFilterSelectItems.add(
          new SelectItem(new Integer(cat.getId().intValue()), cat.getName()));
    }

    // If the selected value now falls out of legal range due to categories
    // being deleted, throw it back to the default value (meaning all categories)
    int selectedCategoryVal = selectedCategoryFilterValue.intValue();
  }
Exemple #3
0
  protected void init() {

    gradebookItemList = new ArrayList();
    courseGrade = new CourseGrade();

    if (getCategoriesEnabled()) {
      /* if categories are enabled, we need to display a table that includes
       * categories, assignments, and the course grade.
       */
      List categoryListWithCG =
          getGradebookManager()
              .getCategoriesWithStats(
                  getGradebookId(),
                  getAssignmentSortColumn(),
                  isAssignmentSortAscending(),
                  getCategorySortColumn(),
                  isCategorySortAscending());
      List<Category> categoryList = new ArrayList<Category>();

      // first, remove the CourseGrade from the Category list
      for (Iterator catIter = categoryListWithCG.iterator(); catIter.hasNext(); ) {
        Object catOrCourseGrade = catIter.next();
        if (catOrCourseGrade instanceof Category) {
          categoryList.add((Category) catOrCourseGrade);
        } else if (catOrCourseGrade instanceof CourseGrade) {
          courseGrade = (CourseGrade) catOrCourseGrade;
        }
      }

      // then, we need to check for special grader permissions that may limit which categories may
      // be viewed
      if (!isUserAbleToGradeAll() && isUserHasGraderPermissions()) {
        // SAK-19896, eduservice's can't share the same "Category" class, so just pass the ID's
        List<Long> catIds = new ArrayList<Long>();
        for (Category category : (List<Category>) categoryList) {
          catIds.add(category.getId());
        }
        List<Long> viewableCats =
            getGradebookPermissionService()
                .getCategoriesForUser(getGradebookId(), getUserUid(), catIds);
        List<Category> tmpCatList = new ArrayList<Category>();
        for (Category category : (List<Category>) categoryList) {
          if (viewableCats.contains(category.getId())) {
            tmpCatList.add(category);
          }
        }
        categoryList = tmpCatList;
      }

      if (categoryList != null && !categoryList.isEmpty()) {
        Comparator catComparator = null;
        if (Assignment.SORT_BY_MEAN.equals(getAssignmentSortColumn())) {
          catComparator = Category.averageScoreComparator;
        } else if (Category.SORT_BY_WEIGHT.equals(getAssignmentSortColumn())) {
          catComparator = Category.weightComparator;
        } else if (Category.SORT_BY_NAME.equals(getAssignmentSortColumn())) {
          catComparator = Category.nameComparator;
        }
        if (catComparator != null) {
          Collections.sort(categoryList, catComparator);
          if (!isAssignmentSortAscending()) {
            Collections.reverse(categoryList);
          }
        }

        Iterator catIter = categoryList.iterator();
        while (catIter.hasNext()) {
          Category myCat = (Category) catIter.next();

          gradebookItemList.add(myCat);
          List assignmentList = myCat.getAssignmentList();
          if (assignmentList != null && !assignmentList.isEmpty()) {
            Iterator assignIter = assignmentList.iterator();
            while (assignIter.hasNext()) {
              Assignment assign = (Assignment) assignIter.next();
              if (assign.isExternallyMaintained()) displayGradeEditorCol = true;
              gradebookItemList.add(assign);
            }
            ensureAssignmentsSorted(assignmentList, GradableObject.sortingComparator, false);
          }
        }
      }

      if (!isUserAbleToGradeAll()
          && (isUserHasGraderPermissions()
              && !getGradebookPermissionService()
                  .getPermissionForUserForAllAssignment(getGradebookId(), getUserUid()))) {
        // is not authorized to view the "Unassigned" Category
      } else {
        List unassignedList =
            getGradebookManager()
                .getAssignmentsWithNoCategoryWithStats(
                    getGradebookId(), getAssignmentSortColumn(), isAssignmentSortAscending());
        if (unassignedList != null && !unassignedList.isEmpty()) {
          Category unassignedCat = new Category();
          unassignedCat.setGradebook(getGradebook());
          unassignedCat.setAverageScore(new Double(0));
          unassignedCat.setName(getLocalizedString("cat_unassigned"));
          unassignedCat.setAssignmentList(unassignedList);
          if (!getWeightingEnabled()) unassignedCat.calculateStatistics(unassignedList);
          gradebookItemList.add(unassignedCat);

          Iterator unassignedIter = unassignedList.iterator();
          while (unassignedIter.hasNext()) {
            Assignment assignWithNoCat = (Assignment) unassignedIter.next();
            if (assignWithNoCat.isExternallyMaintained()) displayGradeEditorCol = true;
            gradebookItemList.add(assignWithNoCat);
          }
        }
        ensureAssignmentsSorted(unassignedList, GradableObject.sortingComparator, false);
      }

    } else {
      // Get the list of assignments for this gradebook, sorted as defined in the overview page.
      List goList =
          getGradebookManager()
              .getAssignmentsAndCourseGradeWithStats(
                  getGradebookId(), getAssignmentSortColumn(), isAssignmentSortAscending());
      if (goList != null && !goList.isEmpty()) {
        Iterator goIter = goList.iterator();
        while (goIter.hasNext()) {
          GradableObject go = (GradableObject) goIter.next();
          if (go.isCourseGrade()) {
            courseGrade = (CourseGrade) go;
          } else {
            Assignment assign = (Assignment) go;
            if (assign.isExternallyMaintained()) displayGradeEditorCol = true;
            gradebookItemList.add(assign);
          }
        }
        ensureAssignmentsSorted(goList, GradableObject.sortingComparator, false);
      }
    }

    // Set up navigation
    ToolSession session = SessionManager.getCurrentToolSession();
    session.setAttribute("breadcrumbPage", "overview");
    session.removeAttribute("adding");
    session.removeAttribute("editing");
    session.removeAttribute("middle");
  }