diff --git a/lib/WeBWorK/Authen/LTIAdvanced/SubmitGrade.pm b/lib/WeBWorK/Authen/LTIAdvanced/SubmitGrade.pm index c7a6285c69..664246ce15 100644 --- a/lib/WeBWorK/Authen/LTIAdvanced/SubmitGrade.pm +++ b/lib/WeBWorK/Authen/LTIAdvanced/SubmitGrade.pm @@ -115,7 +115,7 @@ sub update_sourcedid ($self, $userID) { } # Checks if the set is past the LTISendScoresAfterDate or has met the LTISendGradesEarlyThreshold -sub can_submit_LMS_score ($self, $db, $ce, $userID, $setID) { +sub can_submit_LMS_score ($invocant, $db, $ce, $userID, $setID) { my $userSet = $db->getMergedSet($userID, $setID); if ($ce->{LTISendScoresAfterDate} ne 'never') { @@ -164,6 +164,8 @@ async sub submit_set_grade ($self, $userID, $setID) { my $ce = $c->{ce}; my $db = $c->{db}; + return unless $self->can_submit_LMS_score($db, $ce, $userID, $setID); + my $user = $db->getUser($userID); return 0 unless $user; @@ -175,26 +177,15 @@ async sub submit_set_grade ($self, $userID, $setID) { if !$userSet->lis_source_did && ($ce->{debug_lti_grade_passback} || $self->{post_processing_mode}); my $score; - my $criticalDate; if ($userSet->assignment_type =~ /gateway/) { - $score = scalar(grade_gateway($db, $setID, $userID)); - $criticalDate = earliest_gateway_date($db, $userSet, $ce->{LTISendScoresAfterDate}) - unless ($ce->{LTISendScoresAfterDate} eq 'never'); + $score = scalar(grade_gateway($db, $setID, $userID)); } else { - $score = grade_set($db, $userSet, $userID); - $criticalDate = get_set_date($userSet, $ce->{LTISendScoresAfterDate}) - unless ($ce->{LTISendScoresAfterDate} eq 'never'); - } - - if ($ce->{LTISendScoresAfterDate} eq 'never' || $criticalDate && before($criticalDate)) { - return if ($ce->{LTISendGradesEarlyThreshold} eq 'attempted' && !set_attempted($db, $userID, $setID)); - return if ($ce->{LTISendGradesEarlyThreshold} ne 'attempted' && $score < $ce->{LTISendGradesEarlyThreshold}); + $score = grade_set($db, $userSet, $userID); } return await $self->submit_grade($userSet->lis_source_did, $score, - ($ce->{LTISendScoresAfterDate} eq 'never' || before($criticalDate)) - && ($self->{post_processing_mode} || $ce->{LTIGradeOnSubmit} ne 'homework_always')); + $self->{post_processing_mode} || $ce->{LTIGradeOnSubmit} ne 'homework_always'); } # Submits a score of $score to the lms with $sourcedid as the identifier. diff --git a/lib/WeBWorK/Authen/LTIAdvantage/SubmitGrade.pm b/lib/WeBWorK/Authen/LTIAdvantage/SubmitGrade.pm index ba33c706ea..0bbb0736fc 100644 --- a/lib/WeBWorK/Authen/LTIAdvantage/SubmitGrade.pm +++ b/lib/WeBWorK/Authen/LTIAdvantage/SubmitGrade.pm @@ -193,7 +193,7 @@ async sub get_access_token ($self) { } # Checks if the set is past the LTISendScoresAfterDate or has met the LTISendGradesEarlyThreshold -sub can_submit_LMS_score ($self, $db, $ce, $userID, $setID) { +sub can_submit_LMS_score ($invocant, $db, $ce, $userID, $setID) { my $userSet = $db->getMergedSet($userID, $setID); if ($ce->{LTISendScoresAfterDate} ne 'never') { @@ -243,6 +243,8 @@ async sub submit_set_grade ($self, $userID, $setID) { my $ce = $c->{ce}; my $db = $c->{db}; + return unless $self->can_submit_LMS_score($db, $ce, $userID, $setID); + my $user = $db->getUser($userID); return 0 unless $user; @@ -254,29 +256,15 @@ async sub submit_set_grade ($self, $userID, $setID) { my $totalRight; my $total; - my $criticalDate; if ($userSet->assignment_type =~ /gateway/) { ($totalRight, $total) = grade_gateway($db, $setID, $userID); - $criticalDate = earliest_gateway_date($db, $userSet, $userID, $ce->{LTISendScoresAfterDate}) - unless ($ce->{LTISendScoresAfterDate} eq 'never'); } else { ($totalRight, $total) = (grade_set($db, $userSet, $userID))[ 0, 1 ]; - $criticalDate = get_set_date($userSet, $ce->{LTISendScoresAfterDate}) - unless ($ce->{LTISendScoresAfterDate} eq 'never'); - } - - if ($ce->{LTISendScoresAfterDate} eq 'never' || $criticalDate && before($criticalDate)) { - return if ($ce->{LTISendGradesEarlyThreshold} eq 'attempted' && !set_attempted($db, $userID, $setID)); - return - if ($ce->{LTISendGradesEarlyThreshold} ne 'attempted' - && $total - && $totalRight / $total < $ce->{LTISendGradesEarlyThreshold}); } return await $self->submit_grade($user->lis_source_did, $userSet->lis_source_did, $totalRight, $total, - ($ce->{LTISendScoresAfterDate} eq 'never' || before($criticalDate)) - && ($self->{post_processing_mode} || $ce->{LTIGradeOnSubmit} ne 'homework_always')); + $self->{post_processing_mode} || $ce->{LTIGradeOnSubmit} ne 'homework_always'); } # Submits scoreGiven and scoreMaximum to the lms with $sourcedid as the identifier. diff --git a/lib/WeBWorK/ContentGenerator/GatewayQuiz.pm b/lib/WeBWorK/ContentGenerator/GatewayQuiz.pm index 0b68889269..f320a736c1 100644 --- a/lib/WeBWorK/ContentGenerator/GatewayQuiz.pm +++ b/lib/WeBWorK/ContentGenerator/GatewayQuiz.pm @@ -1024,9 +1024,18 @@ async sub pre_header_initialize ($c) { } # Try to update the student score on the LMS if that option is enabled. - if ($c->{submitAnswers} && $will{recordAnswers} && $ce->{LTIGradeMode} && $ce->{LTIGradeOnSubmit}) { + if ( + $c->{submitAnswers} + && $will{recordAnswers} + && $ce->{LTIGradeMode} + && ($ce->{LTIGradeOnSubmit} eq 'homework_always' && $ce->{LTIGradeMode} eq 'homework' + || $ce->{LTIGradeOnSubmit} + && $ce->{LTI}{ $ce->{LTIVersion} }{grader}->can_submit_LMS_score($db, $ce, $effectiveUserID, $setID) + ) + ) + { my $grader = $ce->{LTI}{ $ce->{LTIVersion} }{grader}->new($c); - if ($ce->{LTIGradeMode} eq 'course' && $grader->can_submit_LMS_score($db, $ce, $effectiveUserID, $setID)) { + if ($ce->{LTIGradeMode} eq 'course') { $LTIGradeResult = await $grader->submit_course_grade($effectiveUserID); } elsif ($ce->{LTIGradeMode} eq 'homework') { $LTIGradeResult = await $grader->submit_set_grade($effectiveUserID, $setID); diff --git a/lib/WeBWorK/Utils/ProblemProcessing.pm b/lib/WeBWorK/Utils/ProblemProcessing.pm index 3cda3c1f9e..f030ee541b 100644 --- a/lib/WeBWorK/Utils/ProblemProcessing.pm +++ b/lib/WeBWorK/Utils/ProblemProcessing.pm @@ -252,12 +252,14 @@ async sub process_and_log_answer ($c) { if ($ce->{LTIGradeMode}) { my $LMSname = $ce->{LTI}{ $ce->{LTIVersion} }{LMS_name}; my $LTIGradeResult = -1; - if ($ce->{LTIGradeOnSubmit}) { + if ($ce->{LTIGradeOnSubmit} eq 'homework_always' && $ce->{LTIGradeMode} eq 'homework' + || $ce->{LTIGradeOnSubmit} + && $ce->{LTI}{ $ce->{LTIVersion} }{grader} + ->can_submit_LMS_score($db, $ce, $problem->user_id, $problem->set_id)) + { $LTIGradeResult = 0; my $grader = $ce->{LTI}{ $ce->{LTIVersion} }{grader}->new($c); - if ($ce->{LTIGradeMode} eq 'course' - && $grader->can_submit_LMS_score($db, $ce, $problem->user_id, $problem->set_id)) - { + if ($ce->{LTIGradeMode} eq 'course') { $LTIGradeResult = await $grader->submit_course_grade($problem->user_id); } elsif ($ce->{LTIGradeMode} eq 'homework') { $LTIGradeResult = await $grader->submit_set_grade($problem->user_id, $problem->set_id);