mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
Merge branch 'MDL-71325' of https://github.com/paulholden/moodle
This commit is contained in:
commit
4c32213446
@ -4,6 +4,8 @@ Information provided here is intended especially for developers.
|
||||
=== 4.3 ===
|
||||
|
||||
* The $showtitle parameter in the print_grade_page_head function located inside grade/lib.php has been deprecated and is not used anymore.
|
||||
* The deprecated `core_grades_create_gradecategory` external method has been removed, in addition to the accompanying
|
||||
`core_grades_external::create_gradecategory` methods
|
||||
|
||||
=== 4.1 ===
|
||||
* The $importactiveurl parameter in the constructor of the core_grades\output\import_action_bar class has been deprecated and is not used anymore.
|
||||
|
@ -188,108 +188,4 @@ class core_grades_external extends external_api {
|
||||
as defined in lib/grade/constants.php'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
*
|
||||
* @deprecated since Moodle 3.11 MDL-71031 - please do not use this function any more.
|
||||
* @todo MDL-71325 This will be deleted in Moodle 4.3.
|
||||
* @see core_grades\external\create_gradecategories::create_gradecategories()
|
||||
*
|
||||
* @return external_function_parameters
|
||||
* @since Moodle 3.10
|
||||
*/
|
||||
public static function create_gradecategory_parameters() {
|
||||
return new external_function_parameters(
|
||||
[
|
||||
'courseid' => new external_value(PARAM_INT, 'id of course', VALUE_REQUIRED),
|
||||
'fullname' => new external_value(PARAM_TEXT, 'fullname of category', VALUE_REQUIRED),
|
||||
'options' => new external_single_structure([
|
||||
'aggregation' => new external_value(PARAM_INT, 'aggregation method', VALUE_OPTIONAL),
|
||||
'aggregateonlygraded' => new external_value(PARAM_BOOL, 'exclude empty grades', VALUE_OPTIONAL),
|
||||
'aggregateoutcomes' => new external_value(PARAM_BOOL, 'aggregate outcomes', VALUE_OPTIONAL),
|
||||
'droplow' => new external_value(PARAM_INT, 'drop low grades', VALUE_OPTIONAL),
|
||||
'itemname' => new external_value(PARAM_TEXT, 'the category total name', VALUE_OPTIONAL),
|
||||
'iteminfo' => new external_value(PARAM_TEXT, 'the category iteminfo', VALUE_OPTIONAL),
|
||||
'idnumber' => new external_value(PARAM_TEXT, 'the category idnumber', VALUE_OPTIONAL),
|
||||
'gradetype' => new external_value(PARAM_INT, 'the grade type', VALUE_OPTIONAL),
|
||||
'grademax' => new external_value(PARAM_INT, 'the grade max', VALUE_OPTIONAL),
|
||||
'grademin' => new external_value(PARAM_INT, 'the grade min', VALUE_OPTIONAL),
|
||||
'gradepass' => new external_value(PARAM_INT, 'the grade to pass', VALUE_OPTIONAL),
|
||||
'display' => new external_value(PARAM_INT, 'the display type', VALUE_OPTIONAL),
|
||||
'decimals' => new external_value(PARAM_INT, 'the decimal count', VALUE_OPTIONAL),
|
||||
'hiddenuntil' => new external_value(PARAM_INT, 'grades hidden until', VALUE_OPTIONAL),
|
||||
'locktime' => new external_value(PARAM_INT, 'lock grades after', VALUE_OPTIONAL),
|
||||
'weightoverride' => new external_value(PARAM_BOOL, 'weight adjusted', VALUE_OPTIONAL),
|
||||
'aggregationcoef2' => new external_value(PARAM_RAW, 'weight coefficient', VALUE_OPTIONAL),
|
||||
'parentcategoryid' => new external_value(PARAM_INT, 'The parent category id', VALUE_OPTIONAL),
|
||||
'parentcategoryidnumber' => new external_value(PARAM_TEXT, 'the parent category idnumber', VALUE_OPTIONAL),
|
||||
], 'optional category data', VALUE_DEFAULT, [])
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a gradecategory inside of the specified course.
|
||||
*
|
||||
* @deprecated since Moodle 3.11 MDL-71031 - please do not use this function any more.
|
||||
* @todo MDL-71325 This will be deleted in Moodle 4.3.
|
||||
* @see core_grades\external\create_gradecategories::create_gradecategories()
|
||||
*
|
||||
* @param int $courseid the courseid to create the gradecategory in.
|
||||
* @param string $fullname the fullname of the grade category to create.
|
||||
* @param array $options array of options to set.
|
||||
*
|
||||
* @return array array of created categoryid and warnings.
|
||||
*/
|
||||
public static function create_gradecategory(int $courseid, string $fullname, array $options) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$params = self::validate_parameters(self::create_gradecategory_parameters(),
|
||||
['courseid' => $courseid, 'fullname' => $fullname, 'options' => $options]);
|
||||
|
||||
// Now params are validated, update the references.
|
||||
$courseid = $params['courseid'];
|
||||
$fullname = $params['fullname'];
|
||||
$options = $params['options'];
|
||||
|
||||
// Check that the context and permissions are OK.
|
||||
$context = context_course::instance($courseid);
|
||||
self::validate_context($context);
|
||||
require_capability('moodle/grade:manage', $context);
|
||||
|
||||
$categories = [];
|
||||
$categories[] = ['fullname' => $fullname, 'options' => $options];
|
||||
// Call through to webservice class for multiple creations,
|
||||
// Where the majority of the this functionality moved with the deprecation of this function.
|
||||
$result = \core_grades\external\create_gradecategories::create_gradecategories_from_data($courseid, $categories);
|
||||
|
||||
return['categoryid' => $result['categoryids'][0], 'warnings' => []];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
*
|
||||
* @deprecated since Moodle 3.11 MDL-71031 - please do not use this function any more.
|
||||
* @todo MDL-71325 This will be deleted in Moodle 4.3.
|
||||
* @see core_grades\external\create_gradecategories::create_gradecategories()
|
||||
*
|
||||
* @return \core_external\external_description
|
||||
* @since Moodle 3.10
|
||||
*/
|
||||
public static function create_gradecategory_returns() {
|
||||
return new external_single_structure([
|
||||
'categoryid' => new external_value(PARAM_INT, 'The ID of the created category', VALUE_OPTIONAL),
|
||||
'warnings' => new external_warnings(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Marking the method as deprecated. See MDL-71031 for details.
|
||||
* @since Moodle 3.11
|
||||
* @return bool
|
||||
*/
|
||||
public static function create_gradecategory_is_deprecated() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -949,14 +949,6 @@ $functions = array(
|
||||
'ajax' => true,
|
||||
'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE],
|
||||
],
|
||||
'core_grades_create_gradecategory' => array (
|
||||
'classname' => 'core_grades_external',
|
||||
'methodname' => 'create_gradecategory',
|
||||
'description' => '** DEPRECATED ** Please do not call this function any more. Use core_grades_create_gradecategories.
|
||||
Create a grade category inside a course gradebook.',
|
||||
'type' => 'write',
|
||||
'capabilities' => 'moodle/grade:manage',
|
||||
),
|
||||
'core_grades_create_gradecategories' => array (
|
||||
'classname' => 'core_grades\external\create_gradecategories',
|
||||
'description' => 'Create grade categories inside a course gradebook.',
|
||||
|
@ -274,83 +274,4 @@ class grades_external_test extends \externallib_advanced_testcase {
|
||||
$grades = grade_get_grades($course->id, 'mod', 'assign', $assignment->id);
|
||||
$this->assertTrue($grades->items[0]->hidden == 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create_gradecategory.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_create_gradecategory() {
|
||||
global $DB;
|
||||
$this->resetAfterTest(true);
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Test the most basic gradecategory creation.
|
||||
$status1 = core_grades_external::create_gradecategory($course->id, 'Test Category 1', []);
|
||||
|
||||
$courseparentcat = new \grade_category(['courseid' => $course->id, 'depth' => 1], true);
|
||||
$record1 = $DB->get_record('grade_categories', ['id' => $status1['categoryid']]);
|
||||
$this->assertEquals('Test Category 1', $record1->fullname);
|
||||
// Confirm that the parent category for this category is the top level category for the course.
|
||||
$this->assertEquals($courseparentcat->id, $record1->parent);
|
||||
$this->assertEquals(2, $record1->depth);
|
||||
|
||||
// Now create a category as a child of the newly created category.
|
||||
$status2 = core_grades_external::create_gradecategory($course->id, 'Test Category 2', ['parentcategoryid' => $record1->id]);
|
||||
$record2 = $DB->get_record('grade_categories', ['id' => $status2['categoryid']]);
|
||||
$this->assertEquals($record1->id, $record2->parent);
|
||||
$this->assertEquals(3, $record2->depth);
|
||||
// Check the path is correct.
|
||||
$this->assertEquals('/' . implode('/', [$courseparentcat->id, $record1->id, $record2->id]) . '/', $record2->path);
|
||||
|
||||
// Now create a category with some customised data and check the returns. This customises every value.
|
||||
$customopts = [
|
||||
'aggregation' => GRADE_AGGREGATE_MEAN,
|
||||
'aggregateonlygraded' => 0,
|
||||
'aggregateoutcomes' => 1,
|
||||
'droplow' => 1,
|
||||
'itemname' => 'item',
|
||||
'iteminfo' => 'info',
|
||||
'idnumber' => 'idnumber',
|
||||
'gradetype' => GRADE_TYPE_TEXT,
|
||||
'grademax' => 5,
|
||||
'grademin' => 2,
|
||||
'gradepass' => 3,
|
||||
'display' => GRADE_DISPLAY_TYPE_LETTER,
|
||||
// Hack. This must be -2 to use the default setting.
|
||||
'decimals' => 3,
|
||||
'hiddenuntil' => time(),
|
||||
'locktime' => time(),
|
||||
'weightoverride' => 1,
|
||||
'aggregationcoef2' => 20,
|
||||
'parentcategoryid' => $record2->id
|
||||
];
|
||||
|
||||
$status3 = core_grades_external::create_gradecategory($course->id, 'Test Category 3', $customopts);
|
||||
$cat3 = new \grade_category(['courseid' => $course->id, 'id' => $status3['categoryid']], true);
|
||||
$cat3->load_grade_item();
|
||||
|
||||
// Lets check all of the data is in the right shape.
|
||||
$this->assertEquals(GRADE_AGGREGATE_MEAN, $cat3->aggregation);
|
||||
$this->assertEquals(0, $cat3->aggregateonlygraded);
|
||||
$this->assertEquals(1, $cat3->aggregateoutcomes);
|
||||
$this->assertEquals(1, $cat3->droplow);
|
||||
$this->assertEquals('item', $cat3->grade_item->itemname);
|
||||
$this->assertEquals('info', $cat3->grade_item->iteminfo);
|
||||
$this->assertEquals('idnumber', $cat3->grade_item->idnumber);
|
||||
$this->assertEquals(GRADE_TYPE_TEXT, $cat3->grade_item->gradetype);
|
||||
$this->assertEquals(5, $cat3->grade_item->grademax);
|
||||
$this->assertEquals(2, $cat3->grade_item->grademin);
|
||||
$this->assertEquals(3, $cat3->grade_item->gradepass);
|
||||
$this->assertEquals(GRADE_DISPLAY_TYPE_LETTER, $cat3->grade_item->display);
|
||||
$this->assertEquals(3, $cat3->grade_item->decimals);
|
||||
$this->assertGreaterThanOrEqual($cat3->grade_item->hidden, time());
|
||||
$this->assertGreaterThanOrEqual($cat3->grade_item->locktime, time());
|
||||
$this->assertEquals(1, $cat3->grade_item->weightoverride);
|
||||
// Coefficient is converted to percentage.
|
||||
$this->assertEquals(0.2, $cat3->grade_item->aggregationcoef2);
|
||||
$this->assertEquals($record2->id, $cat3->parent);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user