From: martinlanghoff Date: Wed, 19 Sep 2007 07:14:23 +0000 (+0000) Subject: course/lib: move_courses() calls content_moved(), intro move_category() X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=19f601d1785bd162754bc9ee035faae10fcf5578;p=moodle.git course/lib: move_courses() calls content_moved(), intro move_category() 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. --- diff --git a/course/lib.php b/course/lib.php index 40d46f4984..c2ef2d25b0 100644 --- a/course/lib.php +++ b/course/lib.php @@ -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