MDL-11582 switch category item only if it is really there

This commit is contained in:
skodak 2007-10-04 08:36:34 +00:00
parent fb72e817d9
commit 3e0e2436de

View File

@ -941,10 +941,13 @@ class grade_tree {
if (count($element['children']) < 2) {
return;
}
$category_item = reset($element['children']);
$order = key($element['children']);
unset($element['children'][$order]);
$element['children'][$order] =& $category_item;
$first_item = reset($element['children']);
if ($first_item['type'] == 'categoryitem') {
// the category item might have been already removed
$order = key($element['children']);
unset($element['children'][$order]);
$element['children'][$order] =& $first_item;
}
foreach ($element['children'] as $sortorder => $child) {
grade_tree::category_grade_last($element['children'][$sortorder]);
}