MDL-68715 completion: fix form default value for course prerequisites.

Adds filtering on the completion criteria form to ensure we are only
selecting actual course instances of this type. Prior to this change
we would also get NULL values from unrelated criteria types.
This commit is contained in:
Paul Holden
2020-06-08 22:39:43 +01:00
parent ee23a8cf25
commit 8acaa4e356
4 changed files with 46 additions and 3 deletions
@@ -0,0 +1,30 @@
@core @core_completion
Feature: Set completion of other courses as criteria for completion of current course
In order to set completion of other courses as criteria for completion of current course
As a user
I want to select the prerequisite courses in completion settings
Background:
Given the following "courses" exist:
| fullname | shortname | category | enablecompletion |
| Course 1 | C1 | 0 | 1 |
| Course 2 | C2 | 0 | 1 |
And the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | One | student1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
@javascript
Scenario: Set completion of prerequisite course as completion criteria of current course
When I log in as "admin"
And I am on "Course 1" course homepage with editing mode on
And I navigate to "Course completion" in current page administration
And I click on "Condition: Completion of other courses" "link"
And I set the field "Courses available" to "Course 2"
And I press "Save changes"
And I add the "Course completion status" block
And I click on "View course report" "link" in the "Course completion status" "block"
Then I should see "Course 2" in the "completion-progress" "table"
And I should see "Student One" in the "completion-progress" "table"
+4 -2
View File
@@ -128,14 +128,16 @@ class course_completion_form extends moodleform {
}
// Get applicable courses (prerequisites).
$selectedcourses = $DB->get_fieldset_sql("SELECT cc.courseinstance
FROM {course_completion_criteria} cc WHERE cc.course = ?", [$course->id]);
$hasselectablecourses = core_course_category::search_courses(['onlywithcompletion' => true], ['limit' => 2]);
unset($hasselectablecourses[$course->id]);
if ($hasselectablecourses) {
// Show multiselect box.
$mform->addElement('course', 'criteria_course', get_string('coursesavailable', 'completion'),
array('multiple' => 'multiple', 'onlywithcompletion' => true, 'exclude' => $course->id));
$mform->setType('criteria_course', PARAM_INT);
$selectedcourses = $DB->get_fieldset_select('course_completion_criteria', 'courseinstance',
'course = :course AND criteriatype = :type', ['course' => $course->id, 'type' => COMPLETION_CRITERIA_TYPE_COURSE]);
$mform->setDefault('criteria_course', $selectedcourses);
// Map aggregation methods to context-sensitive human readable dropdown menu.
+11
View File
@@ -2498,5 +2498,16 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2020062600.01);
}
if ($oldversion < 2020071100.01) {
// Clean up completion criteria records referring to NULL course prerequisites.
$select = 'criteriatype = :type AND courseinstance IS NULL';
$params = ['type' => 8]; // COMPLETION_CRITERIA_TYPE_COURSE.
$DB->delete_records_select('course_completion_criteria', $select, $params);
// Main savepoint reached.
upgrade_main_savepoint(true, 2020071100.01);
}
return true;
}
+1 -1
View File
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2020071100.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2020071100.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.0dev (Build: 20200711)'; // Human-friendly version name