diff --git a/completion/tests/behat/completion_other_courses.feature b/completion/tests/behat/completion_other_courses.feature new file mode 100644 index 00000000000..66765b0954a --- /dev/null +++ b/completion/tests/behat/completion_other_courses.feature @@ -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" diff --git a/course/completion_form.php b/course/completion_form.php index f8501011c90..937a0eee150 100644 --- a/course/completion_form.php +++ b/course/completion_form.php @@ -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. diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index dcc2f48034a..1df218e4e64 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2486,5 +2486,16 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2020061500.02); } + if ($oldversion < 2020061501.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, 2020061501.01); + } + return true; } diff --git a/version.php b/version.php index d84e55c6998..f7cc1973cae 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2020061501.00; // 20200615 = branching date YYYYMMDD - do not modify! +$version = 2020061501.01; // 20200615 = branching date YYYYMMDD - do not modify! // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '3.9.1 (Build: 20200713)'; // Human-friendly version name