From 789029adde7862a492f2d7134e6a12de18bb4f85 Mon Sep 17 00:00:00 2001 From: Angel Nueda Date: Tue, 24 Feb 2015 10:31:06 +0100 Subject: [PATCH] SAK-29103 Associate multiple assignments with the same item gradebook don't delete grades from the old association --- .../assignment/tool/AssignmentAction.java | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/assignment/assignment-tool/tool/src/java/org/sakaiproject/assignment/tool/AssignmentAction.java b/assignment/assignment-tool/tool/src/java/org/sakaiproject/assignment/tool/AssignmentAction.java index 0216a1bf84ae..3f1c5dbdaf81 100644 --- a/assignment/assignment-tool/tool/src/java/org/sakaiproject/assignment/tool/AssignmentAction.java +++ b/assignment/assignment-tool/tool/src/java/org/sakaiproject/assignment/tool/AssignmentAction.java @@ -4723,16 +4723,18 @@ else if ("remove".equals(updateRemoveSubmission)) while (submissions.hasNext()) { AssignmentSubmission aSubmission = (AssignmentSubmission) submissions.next(); - User[] submitters = aSubmission.getSubmitters(); - for (int i=0; submitters != null && i < submitters.length; i++) { - if (isExternalAssociateAssignmentDefined) - { - // if the old associated assignment is an external maintained one - gExternal.updateExternalAssessmentScore(gradebookUid, associateGradebookAssignment, submitters[i].getId(), null); - } - else if (isAssignmentDefined) - { - g.setAssignmentScoreString(gradebookUid, associateGradebookAssignment, submitters[i].getId(), "0", assignmentToolTitle); + if (aSubmission.getGrade(false) != null) { + User[] submitters = aSubmission.getSubmitters(); + for (int i=0; submitters != null && i < submitters.length; i++) { + if (isExternalAssociateAssignmentDefined) + { + // if the old associated assignment is an external maintained one + gExternal.updateExternalAssessmentScore(gradebookUid, associateGradebookAssignment, submitters[i].getId(), null); + } + else if (isAssignmentDefined) + { + g.setAssignmentScoreString(gradebookUid, associateGradebookAssignment, submitters[i].getId(), "0", assignmentToolTitle); + } } } } @@ -8268,6 +8270,9 @@ else if (addtoGradebook.equals(AssignmentService.GRADEBOOK_INTEGRATION_ASSOCIATE // if the assignment has been assoicated with a different entry in gradebook before, remove those grades from the entry in Gradebook if (StringUtils.trimToNull(oAssociateGradebookAssignment) != null && !oAssociateGradebookAssignment.equals(associateGradebookAssignment)) { + // remove all previously associated grades, if any, into Gradebook + integrateGradebook(state, aReference, oAssociateGradebookAssignment, null, null, null, -1, null, null, "remove", category); + // if the old assoicated assignment entry in GB is an external one, but doesn't have anything assoicated with it in Assignment tool, remove it removeNonAssociatedExternalGradebookEntry(context, a.getReference(), oAssociateGradebookAssignment,gExternal, gradebookUid); } @@ -8286,6 +8291,9 @@ else if (addtoGradebook.equals(AssignmentService.GRADEBOOK_INTEGRATION_ASSOCIATE } else { + // remove all previously associated grades, if any, into Gradebook + integrateGradebook(state, aReference, oAssociateGradebookAssignment, null, null, null, -1, null, null, "remove", category); + // need to remove the associated gradebook entry if 1) it is external and 2) no other assignment are associated with it removeNonAssociatedExternalGradebookEntry(context, a.getReference(), oAssociateGradebookAssignment,gExternal, gradebookUid); }