Skip to content

Commit

Permalink
MDL-71796 mod_scorm: fix custom completion logic
Browse files Browse the repository at this point in the history
AMOS BEGIN
 MOV [completiondetail:completionstatuscompletedandpassed,mod_scorm],[completiondetail:completionstatuscompletedorpassed,mod_scorm]
AMOS END
  • Loading branch information
lameze committed Jul 5, 2021
1 parent 3610f1e commit f715595
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
12 changes: 4 additions & 8 deletions mod/scorm/classes/completion/custom_completion.php
Expand Up @@ -67,18 +67,14 @@ public function get_state(string $rule): int {

// Get available status list.
$statuses = array_flip(\scorm_status_options());
$statusbits = 0;

$requiredcompletionstatusid = $this->cm->customdata['customcompletionrules']['completionstatusrequired'] ?? 0;
$isanystatus = ($requiredcompletionstatusid == array_sum($statuses));

// Check at least one track meets the required completion status value(s).
foreach ($tracks as $track) {
if (array_key_exists($track->value, $statuses)) {
$statusbits |= $statuses[$track->value];
}

// All completion status requirements met.
if ($statusbits == $requiredcompletionstatusid) {
if (array_key_exists($track->value, $statuses)
&& ($isanystatus || $statuses[$track->value] == $requiredcompletionstatusid)) {
$status = COMPLETION_COMPLETE;
break;
}
Expand Down Expand Up @@ -193,7 +189,7 @@ public function get_custom_rule_descriptions(): array {
$statusrequired = $statusstrings[$completionstatusid];
} else {
// All statuses required.
$statusrequired = 'completedandpassed';
$statusrequired = 'completedorpassed';
}

return [
Expand Down
2 changes: 1 addition & 1 deletion mod/scorm/lang/en/scorm.php
Expand Up @@ -83,7 +83,7 @@
$string['completed'] = 'Completed';
$string['completiondetail:completionstatuspassed'] = 'Pass the activity';
$string['completiondetail:completionstatuscompleted'] = 'Complete the activity';
$string['completiondetail:completionstatuscompletedandpassed'] = 'Complete and pass the activity';
$string['completiondetail:completionstatuscompletedorpassed'] = 'Complete or pass the activity';
$string['completiondetail:completionscore'] = 'Receive a score of {$a} or more';
$string['completiondetail:allscos'] = 'Do all parts of this activity';
$string['completionscorerequired'] = 'Require minimum score';
Expand Down
6 changes: 3 additions & 3 deletions mod/scorm/tests/behat/scorm_activity_completion.feature
Expand Up @@ -50,7 +50,7 @@ Feature: View activity completion in the SCORM activity
And "Music history" should have the "Receive a score of 3 or more" completion condition
And "Music history" should have the "Do all parts of this activity" completion condition
And "Music history" should have the "Receive a grade" completion condition
And "Music history" should have the "Complete and pass the activity" completion condition
And "Music history" should have the "Complete or pass the activity" completion condition

@javascript
Scenario: View automatic completion items as a student
Expand All @@ -61,7 +61,7 @@ Feature: View activity completion in the SCORM activity
And the "Receive a score of 3 or more" completion condition of "Music history" is displayed as "todo"
And the "Do all parts of this activity" completion condition of "Music history" is displayed as "todo"
And the "Receive a grade" completion condition of "Music history" is displayed as "todo"
And the "Complete and pass the activity" completion condition of "Music history" is displayed as "todo"
And the "Complete or pass the activity" completion condition of "Music history" is displayed as "todo"
And I press "Enter"
And I switch to the main frame
And I click on "Par?" "list_item"
Expand Down Expand Up @@ -93,7 +93,7 @@ Feature: View activity completion in the SCORM activity
And the "Receive a score of 3 or more" completion condition of "Music history" is displayed as "failed"
And the "Do all parts of this activity" completion condition of "Music history" is displayed as "done"
And the "Receive a grade" completion condition of "Music history" is displayed as "done"
And the "Complete and pass the activity" completion condition of "Music history" is displayed as "failed"
And the "Complete or pass the activity" completion condition of "Music history" is displayed as "done"

@javascript
Scenario: Use manual completion
Expand Down
16 changes: 11 additions & 5 deletions mod/scorm/tests/custom_completion_test.php
Expand Up @@ -104,20 +104,26 @@ public function get_state_provider(): array {
'Completion status Completed required, user has completed' => [
'completionstatusrequired', 4, [$completioncompleted], 1, COMPLETION_COMPLETE, null
],
'Completion status Passed and Completed required, user has only completed, can make another attempt' => [
'completionstatusrequired', 6, [$completioncompleted], 0, COMPLETION_INCOMPLETE, null
'Completion status Passed or Completed required, user has only completed, can make another attempt' => [
'completionstatusrequired', 6, [$completioncompleted], 0, COMPLETION_COMPLETE, null
],
'Completion status Passed and Completed required, user has completed and passed' => [
'Completion status Passed or Completed required, user has completed and passed' => [
'completionstatusrequired', 6, [$completionpassed, $completioncompleted], 0, COMPLETION_COMPLETE, null
],
'Completion status Passed or Completed required, user has not passed or completed, but has another attempt' => [
'completionstatusrequired', 6, [$completionincomplete], 2, COMPLETION_INCOMPLETE, null
],
'Completion status Passed or Completed required, user has used all attempts, but not passed or completed' => [
'completionstatusrequired', 6, [$completionincomplete], 1, COMPLETION_COMPLETE_FAIL, null
],
'Completion status Passed required, user has used all attempts and completed, but not passed' => [
'completionstatusrequired', 2, [$completioncompleted], 1, COMPLETION_COMPLETE_FAIL, null
],
'Completion status Completed required, user has used all attempts, but not completed' => [
'completionstatusrequired', 4, [$completionincomplete], 1, COMPLETION_COMPLETE_FAIL, null
],
'Completion status Passed and Completed required, user has used all attempts, but not passed' => [
'completionstatusrequired', 6, [$completionincomplete, $completioncompleted], 2, COMPLETION_COMPLETE_FAIL, null
'Completion status Passed or Completed required, user has used all attempts, but not passed' => [
'completionstatusrequired', 6, [$completionincomplete, $completioncompleted], 2, COMPLETION_COMPLETE, null
],
'Completion score required, user has no score' => [
'completionscorerequired', 80, [], 0, COMPLETION_INCOMPLETE, null
Expand Down

0 comments on commit f715595

Please sign in to comment.