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.
This commit is contained in:
martinlanghoff
2007-09-19 07:14:23 +00:00
parent b4ab7f2ec9
commit 19f601d178
+30 -3
View 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