Search in sources :

Example 36 with Enrollment

use of com.instructure.canvasapi2.models.Enrollment in project instructure-android by instructure.

the class AssignmentDateListRecyclerAdapter method loadData.

@Override
public void loadData() {
    /*Logic regarding MGP is similar here as it is in both assignment recycler adapters,
            if changes are made here, check if they are needed in the other recycler adapters.*/
    Course course = (Course) mCanvasContext;
    // This check is for the "all grading periods" option
    if (mCurrentGradingPeriod != null && mCurrentGradingPeriod.getTitle() != null && mCurrentGradingPeriod.getTitle().equals(getContext().getString(R.string.allGradingPeriods))) {
        loadAssignment();
        return;
    }
    for (Enrollment enrollment : course.getEnrollments()) {
        // Date list is for students
        if (enrollment.isMultipleGradingPeriodsEnabled()) {
            if (mCurrentGradingPeriod == null || mCurrentGradingPeriod.getTitle() == null) {
                // we load current term by setting up the current GP
                mCurrentGradingPeriod = new GradingPeriod();
                mCurrentGradingPeriod.setId(enrollment.getCurrentGradingPeriodId());
                mCurrentGradingPeriod.setTitle(enrollment.getCurrentGradingPeriodTitle());
                // request the grading period objects and make the assignment calls
                // This callback is fulfilled in the grade list fragment.
                CourseManager.getGradingPeriodsForCourse(mGradingPeriodsCallback, course.getId(), true);
                // Then we go ahead and load up the assignments for the current period
                loadAssignmentsForGradingPeriod(mCurrentGradingPeriod.getId(), false);
                return;
            } else {
                // Otherwise we load the info from the currently selected grading period
                loadAssignmentsForGradingPeriod(mCurrentGradingPeriod.getId(), true);
                return;
            }
        }
    }
    // If we made it this far, MGP is disabled so we just go forward with the standard
    loadAssignment();
}
Also used : GradingPeriod(com.instructure.canvasapi2.models.GradingPeriod) Enrollment(com.instructure.canvasapi2.models.Enrollment) Course(com.instructure.canvasapi2.models.Course)

Example 37 with Enrollment

use of com.instructure.canvasapi2.models.Enrollment in project instructure-android by instructure.

the class AssignmentGroupListRecyclerAdapter method loadData.

@Override
public void loadData() {
    /*Logic regarding MGP is similar here as it is in both assignment recycler adapters,
            if changes are made here, check if they are needed in the other recycler adapters.*/
    Course course = (Course) mCanvasContext;
    // This check is for the "all grading periods" option
    if (mCurrentGradingPeriod != null && mCurrentGradingPeriod.getTitle() != null && mCurrentGradingPeriod.getTitle().equals(getContext().getString(R.string.allGradingPeriods))) {
        loadAssignment();
        return;
    }
    for (Enrollment enrollment : course.getEnrollments()) {
        // so we'll check the first student enrollment they have for the course
        if (enrollment.isStudent() && enrollment.isMultipleGradingPeriodsEnabled()) {
            if (mCurrentGradingPeriod == null || mCurrentGradingPeriod.getTitle() == null) {
                // we load current term by setting up the current GP
                mCurrentGradingPeriod = new GradingPeriod();
                mCurrentGradingPeriod.setId(enrollment.getCurrentGradingPeriodId());
                mCurrentGradingPeriod.setTitle(enrollment.getCurrentGradingPeriodTitle());
                // request the grading period objects and make the assignment calls
                // This callback is fulfilled in the grade list fragment.
                CourseManager.getGradingPeriodsForCourse(mGradingPeriodsCallback, course.getId(), true);
                // Then we go ahead and load up the assignments for the current period
                loadAssignmentsForGradingPeriod(mCurrentGradingPeriod.getId(), false);
                return;
            } else {
                // Otherwise we load the info from the currently selected grading period
                loadAssignmentsForGradingPeriod(mCurrentGradingPeriod.getId(), true);
                return;
            }
        }
    }
    // If we made it this far, MGP is disabled so we just go forward with the standard
    loadAssignment();
}
Also used : GradingPeriod(com.instructure.canvasapi2.models.GradingPeriod) Enrollment(com.instructure.canvasapi2.models.Enrollment) Course(com.instructure.canvasapi2.models.Course)

Example 38 with Enrollment

use of com.instructure.canvasapi2.models.Enrollment in project instructure-android by instructure.

the class CourseTest method isObserver_noObserverEnrollment.

@Test
public void isObserver_noObserverEnrollment() {
    Course course = new Course();
    Enrollment enrollment = new Enrollment();
    enrollment.setType("student");
    ArrayList<Enrollment> enrollments = new ArrayList<>();
    enrollments.add(enrollment);
    course.setEnrollments(enrollments);
    assertEquals(false, course.isObserver());
}
Also used : ArrayList(java.util.ArrayList) Enrollment(com.instructure.canvasapi2.models.Enrollment) Course(com.instructure.canvasapi2.models.Course) Test(org.junit.Test)

Example 39 with Enrollment

use of com.instructure.canvasapi2.models.Enrollment in project instructure-android by instructure.

the class CourseTest method courseGrade_currentScoreMGP.

@Test
public void courseGrade_currentScoreMGP() {
    Course course = new Course();
    course.setHasGradingPeriods(true);
    double currentScore = 96.0;
    double finalScore = 47.0;
    Enrollment enrollment = new Enrollment();
    enrollment.setType("student");
    enrollment.setCurrentGradingPeriodId(27);
    enrollment.setMultipleGradingPeriodsEnabled(true);
    enrollment.setCurrentPeriodComputedCurrentScore(currentScore);
    enrollment.setCurrentPeriodComputedFinalScore(finalScore);
    ArrayList<Enrollment> enrollments = new ArrayList<>();
    enrollments.add(enrollment);
    course.setEnrollments(enrollments);
    assertTrue(course.getCourseGrade(false).getCurrentScore() == currentScore);
}
Also used : ArrayList(java.util.ArrayList) Enrollment(com.instructure.canvasapi2.models.Enrollment) Course(com.instructure.canvasapi2.models.Course) Test(org.junit.Test)

Example 40 with Enrollment

use of com.instructure.canvasapi2.models.Enrollment in project instructure-android by instructure.

the class CourseTest method isStudent_noEnrollments.

@Test
public void isStudent_noEnrollments() {
    Course course = new Course();
    course.setEnrollments(new ArrayList<Enrollment>());
    assertEquals(false, course.isStudent());
}
Also used : Enrollment(com.instructure.canvasapi2.models.Enrollment) Course(com.instructure.canvasapi2.models.Course) Test(org.junit.Test)

Aggregations

Enrollment (com.instructure.canvasapi2.models.Enrollment)55 Test (org.junit.Test)46 Course (com.instructure.canvasapi2.models.Course)30 ArrayList (java.util.ArrayList)25 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)7 RestParams (com.instructure.canvasapi2.builders.RestParams)7 NonNull (android.support.annotation.NonNull)4 Grades (com.instructure.canvasapi2.models.Grades)4 StatusCallback (com.instructure.canvasapi2.StatusCallback)3 ExhaustiveListCallback (com.instructure.canvasapi2.utils.ExhaustiveListCallback)3 List (java.util.List)3 GradingPeriod (com.instructure.canvasapi2.models.GradingPeriod)2 User (com.instructure.canvasapi2.models.User)2 Application (android.app.Application)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 View (android.view.View)1 BasicUser (com.instructure.canvasapi2.models.BasicUser)1 ErrorReportResult (com.instructure.canvasapi2.models.ErrorReportResult)1 ApiType (com.instructure.canvasapi2.utils.ApiType)1