]> git.mjollnir.org Git - moodle.git/commitdiff
course/lib: move_courses() calls content_moved(), intro move_category()
authormartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:14:23 +0000 (07:14 +0000)
committermartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:14:23 +0000 (07:14 +0000)
move_courses() now calls content_moved() which will take care of any
accesslib-required changes. And introducing move_category() which
also calls content_moved() when needed.

course/lib.php

index 40d46f4984bee0075750b442fc9c97a5e412443a..c2ef2d25b0cbcff7f84ba5bb0394991441ba13a6 100644 (file)
@@ -2635,9 +2635,10 @@ function move_courses ($courseids, $categoryid) {
                     if (!update_record('course', $course)) {
                         notify("An error occurred - course not moved!");
                     }
-                    // parents changed (course category)
-                    // rebuild this context and all children
-                    rebuild_context_rel(get_context_instance(CONTEXT_COURSE, $course->id));
+
+                    $context   = get_context_instance(CONTEXT_COURSE, $course->id);
+                    $newparent = get_context_instance(CONTEXT_COURSECAT, $course->category);
+                    context_moved($context, $newparent);
                 }
             }
             fix_course_sortorder();
@@ -2645,6 +2646,32 @@ function move_courses ($courseids, $categoryid) {
     return true;
 }
 
+/***
+ *** Efficiently moves a category - NOTE that this can have
+ *** a huge impact access-control-wise...
+ ***
+ ***
+ **/
+function move_category ($category, $newparentcat) {
+
+    global $CFG;
+
+    if (!set_field('course_categories', 'parent', $newparentcat->id, 'id', $category->id)) {
+        return false;
+    }
+
+    $context   = get_context_instance(CONTEXT_COURSECAT, $category->id);
+    $newparent = get_context_instance(CONTEXT_COURSECAT, $newparentcat->id);
+    context_moved($context, $newparent);
+
+    // The most effective thing would be to find the common parent, 
+    // until then, do it sitewide...
+    fix_course_sortorder();
+    
+
+    return true;
+}
+
 /**
  * @param string $format Course format ID e.g. 'weeks'
  * @return Name that the course format prefers for sections