Skip to content

Commit

Permalink
Merge branch 'MDL-78527-master' of https://github.com/aanabit/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Sep 13, 2023
2 parents 3849e57 + b87b721 commit 6c6a655
Show file tree
Hide file tree
Showing 79 changed files with 607 additions and 381 deletions.
Expand Up @@ -97,7 +97,7 @@ Feature: Confirm that availability_completion works with previous activity setti
When I open "Page2" actions menu
And I click on "Edit settings" "link" in the "Page2" activity
And I set the following fields to these values:
| Completion tracking | Do not indicate activity completion |
| None | 1 |
And I press "Save and return to course"
When I turn editing mode off
Then I should see "Not available unless: The activity Page1 is marked complete" in the "region-main" "region"
Expand Down Expand Up @@ -197,7 +197,7 @@ Feature: Confirm that availability_completion works with previous activity setti
And I open "Page3" actions menu
And I click on "Edit settings" "link" in the "Page3" activity
And I set the following fields to these values:
| Completion tracking | Do not indicate activity completion |
| None | 1 |
And I press "Save and return to course"

When I turn editing mode off
Expand Down
Expand Up @@ -42,8 +42,8 @@ Feature: Enable Block Completion in a course
And I follow "Test page name"
And I navigate to "Settings" in current page administration
And I set the following fields to these values:
| Completion tracking | Show activity as complete when conditions are met |
| Require view | 1 |
| Add requirements | 1 |
| View the activity | 1 |
And I press "Save and return to course"
When I add the "Course completion status" block
And I navigate to "Course completion" in current page administration
Expand Down
@@ -1,4 +1,4 @@
@block @block_completionstatus
@block @block_completionstatus @core_completion
Feature: Enable Block Completion in a course using activity completion
In order to view the completion block in a course
As a teacher
Expand Down Expand Up @@ -27,8 +27,8 @@ Feature: Enable Block Completion in a course using activity completion
And I follow "Test page name"
And I navigate to "Settings" in current page administration
And I set the following fields to these values:
| Completion tracking | Show activity as complete when conditions are met |
| Require view | 1 |
| Add requirements | 1 |
| View the activity | 1 |
And I press "Save and return to course"
And I add the "Course completion status" block
And I navigate to "Course completion" in current page administration
Expand All @@ -48,8 +48,8 @@ Feature: Enable Block Completion in a course using activity completion
And I follow "Test page name"
And I navigate to "Settings" in current page administration
And I set the following fields to these values:
| Completion tracking | Show activity as complete when conditions are met |
| Require view | 1 |
| Add requirements | 1 |
| View the activity | 1 |
And I press "Save and return to course"
And I add the "Course completion status" block
And I navigate to "Course completion" in current page administration
Expand All @@ -72,10 +72,10 @@ Feature: Enable Block Completion in a course using activity completion
Given I am on the "Test assign name" "assign activity" page logged in as teacher1
And I navigate to "Settings" in current page administration
And I set the following fields to these values:
| Completion tracking | Show activity as complete when conditions are met |
| completionusegrade | 1 |
| completionpassgrade | 1 |
| gradepass | 50 |
| Add requirements | 1 |
| Receive a grade | 1 |
| Passing grade | 1 |
| gradepass | 50 |
And I press "Save and return to course"
And I am on the "Test assign name" "assign activity" page
And I follow "View all submissions"
Expand Down Expand Up @@ -106,10 +106,10 @@ Feature: Enable Block Completion in a course using activity completion
Given I am on the "Test assign name" "assign activity" page logged in as teacher1
And I navigate to "Settings" in current page administration
And I set the following fields to these values:
| Completion tracking | Show activity as complete when conditions are met |
| completionusegrade | 1 |
| completionpassgrade | 1 |
| gradepass | 50 |
| Add requirements | 1 |
| Receive a grade | 1 |
| Passing grade | 1 |
| gradepass | 50 |
And I press "Save and return to course"
And I am on the "Test assign name" "assign activity" page
And I follow "View all submissions"
Expand Down
Expand Up @@ -30,7 +30,7 @@ Feature: Course overview block show users their progress on courses
Given I am on the "Test choice 1" "choice activity" page logged in as teacher1
And I navigate to "Settings" in current page administration
And I set the following fields to these values:
| Completion tracking | Show activity as complete when conditions are met |
| Add requirements | 1 |
| id_completionview | 1 |
And I press "Save and return to course"
And I log out
Expand Down
52 changes: 45 additions & 7 deletions completion/classes/edit_base_form.php
Expand Up @@ -99,18 +99,23 @@ abstract protected function get_module_form();
*
* @return array
*/
protected function add_completion_rules() {
protected function add_custom_completion(string $function): array {
$modnames = array_keys($this->get_module_names());

if (count($modnames) != 1 || !plugin_supports('mod', $modnames[0], FEATURE_COMPLETION_HAS_RULES, false)) {
return [];
return [false, []];
}

$component = "mod_{$modnames[0]}";
$itemnames = \core_grades\component_gradeitems::get_itemname_mapping_for_component($component);
$hascustomrules = count($itemnames) > 1;

try {
// Add completion rules from the module form to this form.
$moduleform = $this->get_module_form();
$moduleform->_form = $this->_form;
if ($customcompletionelements = $moduleform->add_completion_rules()) {
$this->hascustomrules = true;
if ($customcompletionelements = $moduleform->{$function}()) {
$hascustomrules = true;
foreach ($customcompletionelements as $customcompletionelement) {
// Instead of checking for the suffix at the end of the element name, we need to check for its presence
// because some modules, like SCORM, are adding things at the end.
Expand All @@ -123,16 +128,35 @@ protected function add_completion_rules() {
$moduleform->_form->removeElement($customcompletionelement);
}
}

}
return $customcompletionelements;
return [$hascustomrules, $customcompletionelements];
} catch (Exception $e) {
debugging('Could not add custom completion rule of module ' . $modnames[0] .
' to this form, this has to be fixed by the developer', DEBUG_DEVELOPER);
return [];
return [$hascustomrules, $customcompletionelements];
}
}

/**
* If all selected modules are of the same module type, adds custom completion rules from this module type
*
* @return array
*/
protected function add_completion_rules() {
list($hascustomrules, $customcompletionelements) = $this->add_custom_completion('add_completion_rules');
if (!$this->hascustomrules && $hascustomrules) {
$this->hascustomrules = true;
}

$component = "mod_{$this->get_module_name()}";
$itemnames = \core_grades\component_gradeitems::get_itemname_mapping_for_component($component);
if (count($itemnames) > 1) {
$customcompletionelements[] = 'completiongradeitemnumber';
}

return $customcompletionelements;
}

/**
* Checks if at least one of the custom completion rules is enabled
*
Expand All @@ -147,6 +171,20 @@ protected function completion_rule_enabled($data) {
return false;
}

/**
* If all selected modules are of the same module type, adds custom completion rules from this module type
*
* @return array
*/
public function add_completiongrade_rules(): array {
list($hascustomrules, $customcompletionelements) = $this->add_custom_completion('add_completiongrade_rules');
if (!$this->hascustomrules && $hascustomrules) {
$this->hascustomrules = true;
}

return $customcompletionelements;
}

/**
* Returns list of modules that have automatic completion rules that are not shown on this form
* (because they are not present in at least one other selected module).
Expand Down

0 comments on commit 6c6a655

Please sign in to comment.