Merge branch 'MDL-29044-master-3' of git://git.luns.net.uk/moodle
[moodle.git] / course / lib.php
index 382ae35..f96e893 100644 (file)
@@ -3957,6 +3957,32 @@ function create_course($data, $editoroptions = NULL) {
     return $course;
 }
 
+/**
+ * Create a new course category and marks the context as dirty
+ *
+ * This function does not set the sortorder for the new category and
+ * @see{fix_course_sortorder} should be called after creating a new course
+ * category
+ *
+ * Please note that this function does not verify access control.
+ *
+ * @param object $category All of the data required for an entry in the course_categories table
+ * @return object new course category
+ */
+function create_course_category($category) {
+    global $DB;
+
+    $category->timemodified = time();
+    $category->id = $DB->insert_record('course_categories', $category);
+    $category = $DB->get_record('course_categories', array('id' => $category->id));
+
+    // We should mark the context as dirty
+    $category->context = context_coursecat::instance($category->id);
+    $category->context->mark_dirty();
+
+    return $category;
+}
+
 /**
  * Update a course.
  *