mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 18:06:51 +02:00
MDL-52206 core: Add completion criteria to course_modules
This commit is contained in:
parent
663137748e
commit
90acd8d381
19 changed files with 113 additions and 17 deletions
|
@ -711,7 +711,16 @@ class completion_info {
|
|||
// Check grade
|
||||
if (!is_null($cminfo->completiongradeitemnumber)) {
|
||||
$newstate = $this->get_grade_completion($cminfo, $userid);
|
||||
if ($newstate == COMPLETION_INCOMPLETE) {
|
||||
if ($cm->completionpassgrade) {
|
||||
// If we are asking to use pass grade completion but haven't set it,
|
||||
// then default to COMPLETION_COMPLETE_PASS.
|
||||
if ($newstate == COMPLETION_COMPLETE) {
|
||||
return COMPLETION_COMPLETE_PASS;
|
||||
} else if ($newstate != COMPLETION_COMPLETE_PASS) {
|
||||
// Mark as incomplete if there is no grade provided or the grade has failed.
|
||||
$newstate = COMPLETION_INCOMPLETE;
|
||||
}
|
||||
} else if ($newstate == COMPLETION_INCOMPLETE) {
|
||||
return COMPLETION_INCOMPLETE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2878,5 +2878,19 @@ function xmldb_main_upgrade($oldversion) {
|
|||
upgrade_main_savepoint(true, 2021100300.01);
|
||||
}
|
||||
|
||||
if ($oldversion < 2021100300.02) {
|
||||
$table = new xmldb_table('course_modules');
|
||||
|
||||
// Adding new fields to table course_module table.
|
||||
$field = new xmldb_field('completionpassgrade', XMLDB_TYPE_INTEGER, '1', null,
|
||||
XMLDB_NOTNULL, null, '0', 'completionexpected');
|
||||
// Conditionally launch create table for course_completion_defaults.
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
upgrade_main_savepoint(true, 2021100300.02);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -970,6 +970,12 @@ class cm_info implements IteratorAggregate {
|
|||
*/
|
||||
private $completiongradeitemnumber;
|
||||
|
||||
/**
|
||||
* 1 if pass grade completion is enabled, 0 otherwise - from course_modules table
|
||||
* @var int
|
||||
*/
|
||||
private $completionpassgrade;
|
||||
|
||||
/**
|
||||
* 1 if 'on view' completion is enabled, 0 otherwise - from course_modules table
|
||||
* @var int
|
||||
|
@ -1173,6 +1179,7 @@ class cm_info implements IteratorAggregate {
|
|||
'completion' => false,
|
||||
'completionexpected' => false,
|
||||
'completiongradeitemnumber' => false,
|
||||
'completionpassgrade' => false,
|
||||
'completionview' => false,
|
||||
'conditionscompletion' => false,
|
||||
'conditionsfield' => false,
|
||||
|
@ -1648,7 +1655,7 @@ class cm_info implements IteratorAggregate {
|
|||
// Standard fields from table course_modules.
|
||||
static $cmfields = array('id', 'course', 'module', 'instance', 'section', 'idnumber', 'added',
|
||||
'score', 'indent', 'visible', 'visibleoncoursepage', 'visibleold', 'groupmode', 'groupingid',
|
||||
'completion', 'completiongradeitemnumber', 'completionview', 'completionexpected',
|
||||
'completion', 'completiongradeitemnumber', 'completionview', 'completionexpected', 'completionpassgrade',
|
||||
'showdescription', 'availability', 'deletioninprogress');
|
||||
foreach ($cmfields as $key) {
|
||||
$cmrecord->$key = $this->$key;
|
||||
|
@ -1867,6 +1874,7 @@ class cm_info implements IteratorAggregate {
|
|||
// availability and completion fields, even if availability or completion
|
||||
// are actually disabled
|
||||
$this->completion = isset($mod->completion) ? $mod->completion : 0;
|
||||
$this->completionpassgrade = isset($mod->completionpassgrade) ? $mod->completionpassgrade : 0;
|
||||
$this->completiongradeitemnumber = isset($mod->completiongradeitemnumber)
|
||||
? $mod->completiongradeitemnumber : null;
|
||||
$this->completionview = isset($mod->completionview)
|
||||
|
|
|
@ -176,7 +176,7 @@ abstract class testing_module_generator extends component_generator_base {
|
|||
$easymergefields = array('section', 'added', 'score', 'indent',
|
||||
'visible', 'visibleold', 'groupmode', 'groupingid',
|
||||
'completion', 'completiongradeitemnumber', 'completionview', 'completionexpected',
|
||||
'availability', 'showdescription');
|
||||
'completionpassgrade', 'availability', 'showdescription');
|
||||
foreach ($easymergefields as $key) {
|
||||
if (isset($options[$key])) {
|
||||
$moduleinfo->$key = $options[$key];
|
||||
|
@ -195,6 +195,7 @@ abstract class testing_module_generator extends component_generator_base {
|
|||
'completion' => 0,
|
||||
'completionview' => 0,
|
||||
'completionexpected' => 0,
|
||||
'completionpassgrade' => 0,
|
||||
'conditiongradegroup' => array(),
|
||||
'conditionfieldgroup' => array(),
|
||||
'conditioncompletiongroup' => array()
|
||||
|
|
|
@ -258,6 +258,7 @@ class core_test_generator_testcase extends advanced_testcase {
|
|||
'completion' => COMPLETION_TRACKING_AUTOMATIC, // "Show activity as complete when conditions are met."
|
||||
'completionview' => 1, // "Student must view this activity to complete it"
|
||||
'completionusegrade' => 1, // "Student must receive a grade to complete this activity"
|
||||
'completionpassgrade' => 1, // "Student must receive a passing grade to complete this activity"
|
||||
);
|
||||
|
||||
// Module supports FEATURE_RATE:
|
||||
|
@ -327,6 +328,7 @@ class core_test_generator_testcase extends advanced_testcase {
|
|||
$cm3 = $modinfo->cms[$m3->cmid];
|
||||
$this->assertEquals($featurecompletionautomatic['completion'], $cm3->completion);
|
||||
$this->assertEquals($featurecompletionautomatic['completionview'], $cm3->completionview);
|
||||
$this->assertEquals($featurecompletionautomatic['completionpassgrade'], $cm3->completionpassgrade);
|
||||
$this->assertEquals(0, $cm3->completiongradeitemnumber); // Zero instead of default null since 'completionusegrade' was set.
|
||||
$gradingitem = grade_item::fetch(array('courseid'=>$course->id, 'itemtype'=>'mod', 'itemmodule' => 'assign', 'iteminstance' => $m3->id));
|
||||
$this->assertEquals(0, $gradingitem->grademin);
|
||||
|
|
|
@ -725,6 +725,7 @@ class core_completionlib_testcase extends advanced_testcase {
|
|||
'completion' => COMPLETION_TRACKING_AUTOMATIC,
|
||||
// Submission grade required.
|
||||
'completiongradeitemnumber' => 0,
|
||||
'completionpassgrade' => 1,
|
||||
]);
|
||||
|
||||
$cmworkshop = cm_info::create(get_coursemodule_from_instance('workshop', $workshop->id));
|
||||
|
@ -756,8 +757,10 @@ class core_completionlib_testcase extends advanced_testcase {
|
|||
$workshopcompletiondata = $method->invoke($completioninfo, $cmworkshop, $user->id);
|
||||
|
||||
$this->assertArrayHasKey('completiongrade', $workshopcompletiondata);
|
||||
$this->assertArrayHasKey('passgrade', $workshopcompletiondata);
|
||||
$this->assertArrayNotHasKey('customcompletion', $workshopcompletiondata);
|
||||
$this->assertEquals(COMPLETION_INCOMPLETE, $workshopcompletiondata['completiongrade']);
|
||||
$this->assertEquals(COMPLETION_INCOMPLETE, $workshopcompletiondata['passgrade']);
|
||||
|
||||
// Check that fetching data for a module with no completion conditions does not provide any data.
|
||||
$choice2completiondata = $method->invoke($completioninfo, $cmchoice2, $user->id);
|
||||
|
|
|
@ -183,6 +183,7 @@ class modinfolib_test extends advanced_testcase {
|
|||
$this->assertEquals($moduledb->indent, $cm->indent);
|
||||
$this->assertEquals($moduledb->completion, $cm->completion);
|
||||
$this->assertEquals($moduledb->completiongradeitemnumber, $cm->completiongradeitemnumber);
|
||||
$this->assertEquals($moduledb->completionpassgrade, $cm->completionpassgrade);
|
||||
$this->assertEquals($moduledb->completionview, $cm->completionview);
|
||||
$this->assertEquals($moduledb->completionexpected, $cm->completionexpected);
|
||||
$this->assertEquals($moduledb->showdescription, $cm->showdescription);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue