Merge branch 'MDL-33528' of git://github.com/mouneyrac/moodle
This commit is contained in:
+21
-19
@@ -1188,7 +1188,9 @@ class core_course_external extends external_api {
|
||||
array(
|
||||
'name' => new external_value(PARAM_TEXT, 'new category name'),
|
||||
'parent' => new external_value(PARAM_INT,
|
||||
'the parent category id inside which the new category will be created'),
|
||||
'the parent category id inside which the new category will be created
|
||||
- set to 0 for a root category',
|
||||
VALUE_DEFAULT, 0),
|
||||
'idnumber' => new external_value(PARAM_RAW,
|
||||
'the new category idnumber', VALUE_OPTIONAL),
|
||||
'description' => new external_value(PARAM_RAW,
|
||||
@@ -1233,6 +1235,23 @@ class core_course_external extends external_api {
|
||||
self::validate_context($context);
|
||||
require_capability('moodle/category:manage', $context);
|
||||
|
||||
// Check name.
|
||||
if (textlib::strlen($category['name'])>255) {
|
||||
throw new moodle_exception('categorytoolong');
|
||||
}
|
||||
|
||||
$newcategory = new stdClass();
|
||||
$newcategory->name = $category['name'];
|
||||
$newcategory->parent = $category['parent'];
|
||||
$newcategory->sortorder = 999; // Same as in the course/editcategory.php .
|
||||
// Format the description.
|
||||
if (!empty($category['description'])) {
|
||||
$newcategory->description = $category['description'];
|
||||
}
|
||||
$newcategory->descriptionformat = external_validate_format($category['descriptionformat']);
|
||||
if (isset($category['theme']) and !empty($CFG->allowcategorythemes)) {
|
||||
$newcategory->theme = $category['theme'];
|
||||
}
|
||||
// Check id number.
|
||||
if (!empty($category['idnumber'])) { // Same as in course/editcategory_form.php .
|
||||
if (textlib::strlen($category['idnumber'])>100) {
|
||||
@@ -1243,24 +1262,7 @@ class core_course_external extends external_api {
|
||||
throw new moodle_exception('idnumbertaken');
|
||||
}
|
||||
}
|
||||
}
|
||||
// Check name.
|
||||
if (textlib::strlen($category['name'])>255) {
|
||||
throw new moodle_exception('categorytoolong');
|
||||
}
|
||||
|
||||
$newcategory = new stdClass();
|
||||
$newcategory->name = $category['name'];
|
||||
$newcategory->parent = $category['parent'];
|
||||
$newcategory->idnumber = $category['idnumber'];
|
||||
$newcategory->sortorder = 999; // Same as in the course/editcategory.php .
|
||||
// Format the description.
|
||||
if (!empty($category['description'])) {
|
||||
$newcategory->description = $category['description'];
|
||||
}
|
||||
$newcategory->descriptionformat = external_validate_format($category['descriptionformat']);
|
||||
if (isset($category['theme']) and !empty($CFG->allowcategorythemes)) {
|
||||
$newcategory->theme = $category['theme'];
|
||||
$newcategory->idnumber = $category['idnumber'];
|
||||
}
|
||||
|
||||
$newcategory = create_course_category($newcategory);
|
||||
|
||||
Reference in New Issue
Block a user