MDL-53568 tool_lp: Fix getting proficiency of grade not in scaleconfig
This commit is contained in:
@@ -397,7 +397,7 @@ class competency_framework extends persistent {
|
||||
}
|
||||
}
|
||||
|
||||
throw new coding_exception('Grade not found in configuration.');
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2014,12 +2014,10 @@ class tool_lp_api_testcase extends advanced_testcase {
|
||||
$u1ctx = context_user::instance($u1->id);
|
||||
$scale = $dg->create_scale(array('scale' => 'A,B,C,D'));
|
||||
$scaleconfig = array(array('scaleid' => $scale->id));
|
||||
$scaleconfig[] = array('name' => 'A', 'id' => 1, 'scaledefault' => 0, 'proficient' => 0);
|
||||
$scaleconfig[] = array('name' => 'B', 'id' => 2, 'scaledefault' => 1, 'proficient' => 0);
|
||||
$scaleconfig[] = array('name' => 'C', 'id' => 3, 'scaledefault' => 0, 'proficient' => 1);
|
||||
$scaleconfig[] = array('name' => 'D', 'id' => 4, 'scaledefault' => 0, 'proficient' => 1);
|
||||
$c2scaleconfig = array(array('scaleid' => $scale->id));
|
||||
$c2scaleconfig[] = array('name' => 'A', 'id' => 1, 'scaledefault' => 0, 'proficient' => 0);
|
||||
$c2scaleconfig[] = array('name' => 'B', 'id' => 2, 'scaledefault' => 0, 'proficient' => 1);
|
||||
$c2scaleconfig[] = array('name' => 'C', 'id' => 3, 'scaledefault' => 0, 'proficient' => 0);
|
||||
$c2scaleconfig[] = array('name' => 'D', 'id' => 4, 'scaledefault' => 1, 'proficient' => 1);
|
||||
@@ -2785,9 +2783,7 @@ class tool_lp_api_testcase extends advanced_testcase {
|
||||
$scaleconfiguration1 = '[{"scaleid":"1"},{"name":"value1","id":1,"scaledefault":1,"proficient":0},' .
|
||||
'{"name":"value2","id":2,"scaledefault":0,"proficient":1}]';
|
||||
$scaleconfiguration2 = '[{"scaleid":"2"},{"name":"value3","id":1,"scaledefault":1,"proficient":0},'
|
||||
. '{"name":"value4","id":2,"scaledefault":0,"proficient":1},'
|
||||
. '{"name":"value5","id":3,"scaledefault":0,"proficient":0},'
|
||||
. '{"name":"value6","id":4,"scaledefault":0,"proficient":0}]';
|
||||
. '{"name":"value4","id":2,"scaledefault":0,"proficient":1}]';
|
||||
|
||||
// Create a framework with scale configuration1.
|
||||
$frm = array(
|
||||
|
||||
@@ -162,15 +162,21 @@ class tool_lp_generator extends component_generator_base {
|
||||
if (count($values) < 2) {
|
||||
throw new coding_exception('Please provide the scale configuration for one-item scales.');
|
||||
}
|
||||
$scaleconfig = array(array('scaleid' => $record->scaleid));
|
||||
foreach ($values as $key => $value) {
|
||||
$scaleconfig[] = array(
|
||||
'name' => $value['name'],
|
||||
'id' => $value['id'],
|
||||
'scaledefault' => $key == count($values) - 2 ? 1 : 0, // Second to last is default.
|
||||
'proficient' => $key >= count($values) - 2 ? 1 : 0, // Second to last and last are proficient.
|
||||
);
|
||||
}
|
||||
$scaleconfig = array();
|
||||
// Last item is proficient.
|
||||
$item = array_pop($values);
|
||||
array_unshift($scaleconfig, array(
|
||||
'id' => $item['id'],
|
||||
'proficient' => 1
|
||||
));
|
||||
// Second-last item is default and proficient.
|
||||
$item = array_pop($values);
|
||||
array_unshift($scaleconfig, array(
|
||||
'id' => $item['id'],
|
||||
'scaledefault' => 1,
|
||||
'proficient' => 1
|
||||
));
|
||||
array_unshift($scaleconfig, array('scaleid' => $record->scaleid));
|
||||
$record->scaleconfiguration = json_encode($scaleconfig);
|
||||
}
|
||||
if (is_array($record->scaleconfiguration) || is_object($record->scaleconfiguration)) {
|
||||
|
||||
Reference in New Issue
Block a user