diff --git a/course/category.php b/course/category.php index 935b83a..ce4864a 100644 --- a/course/category.php +++ b/course/category.php @@ -39,6 +39,7 @@ $movedown = optional_param('movedown', 0, PARAM_INT); $moveto = optional_param('moveto', 0, PARAM_INT); $resort = optional_param('resort', 0, PARAM_BOOL); $sesskey = optional_param('sesskey', '', PARAM_RAW); +$resort_cat = optional_param('resort_cat', 0, PARAM_BOOL); //marx if (empty($id)) { print_error("unknowcategory"); @@ -72,11 +73,19 @@ if (!$category->visible) { $canmanage = has_capability('moodle/category:manage', $context); $sesskeyprovided = !empty($sesskey) && confirm_sesskey($sesskey); +//compares strings naturally in object keys +function cmp($a, $b) +{ + return strnatcmp($a->fullname, $b->fullname); +} + // Process any category actions. if ($canmanage && $resort && $sesskeyprovided) { // Resort the category if requested if ($courses = get_courses($category->id, "fullname ASC", 'c.id,c.fullname,c.sortorder')) { $i = 1; + //natural sort on course fullname + usort($courses, 'cmp'); foreach ($courses as $course) { $DB->set_field('course', 'sortorder', $category->sortorder+$i, array('id'=>$course->id)); $i++;