function _fetch_course_tree_recursion($category_array, &$sortorder) { // update the sortorder in db if needed if ($category_array['object']->sortorder != $sortorder) { $category_array['object']->set_sortorder($sortorder); } // store the grade_item or grade_category instance with extra info $result = array('object' => $category_array['object'], 'type' => $category_array['type'], 'depth' => $category_array['depth']); // reuse final grades if there if (array_key_exists('finalgrades', $category_array)) { $result['finalgrades'] = $category_array['finalgrades']; } // recursively resort children if (!empty($category_array['children'])) { $result['children'] = array(); //process the category item first $cat_item_id = null; foreach ($category_array['children'] as $oldorder => $child_array) { if ($child_array['type'] == 'courseitem' or $child_array['type'] == 'categoryitem') { $result['children'][$sortorder] = grade_category::_fetch_course_tree_recursion($child_array, $sortorder); } } foreach ($category_array['children'] as $oldorder => $child_array) { if ($child_array['type'] != 'courseitem' and $child_array['type'] != 'categoryitem') { $result['children'][++$sortorder] = grade_category::_fetch_course_tree_recursion($child_array, $sortorder); } } } return $result; }
/** * An internal function that recursively sorts grade categories within a course * * @param array $category_array The seed of the recursion * @param int $sortorder The current sortorder * @return array An array containing 'object', 'type', 'depth' and optionally 'children' */ private static function _fetch_course_tree_recursion($category_array, &$sortorder) { // update the sortorder in db if needed //NOTE: This leads to us resetting sort orders every time the categories and items page is viewed :( //if ($category_array['object']->sortorder != $sortorder) { //$category_array['object']->set_sortorder($sortorder); //} if (isset($category_array['object']->gradetype) && $category_array['object']->gradetype == GRADE_TYPE_NONE) { return null; } // store the grade_item or grade_category instance with extra info $result = array('object' => $category_array['object'], 'type' => $category_array['type'], 'depth' => $category_array['depth']); // reuse final grades if there if (array_key_exists('finalgrades', $category_array)) { $result['finalgrades'] = $category_array['finalgrades']; } // recursively resort children if (!empty($category_array['children'])) { $result['children'] = array(); //process the category item first $child = null; foreach ($category_array['children'] as $oldorder => $child_array) { if ($child_array['type'] == 'courseitem' or $child_array['type'] == 'categoryitem') { $child = grade_category::_fetch_course_tree_recursion($child_array, $sortorder); if (!empty($child)) { $result['children'][$sortorder] = $child; } } } foreach ($category_array['children'] as $oldorder => $child_array) { if ($child_array['type'] != 'courseitem' and $child_array['type'] != 'categoryitem') { $child = grade_category::_fetch_course_tree_recursion($child_array, $sortorder); if (!empty($child)) { $result['children'][++$sortorder] = $child; } } } } return $result; }
/** * An internal function that recursively sorts grade categories within a course * * @param array $category_array The seed of the recursion * @param int $sortorder The current sortorder * @return array An array containing 'object', 'type', 'depth' and optionally 'children' */ private static function _fetch_course_tree_recursion($category_array, &$sortorder) { if (isset($category_array['object']->gradetype) && $category_array['object']->gradetype == GRADE_TYPE_NONE) { return null; } // store the grade_item or grade_category instance with extra info $result = array('object' => $category_array['object'], 'type' => $category_array['type'], 'depth' => $category_array['depth']); // reuse final grades if there if (array_key_exists('finalgrades', $category_array)) { $result['finalgrades'] = $category_array['finalgrades']; } // recursively resort children if (!empty($category_array['children'])) { $result['children'] = array(); //process the category item first $child = null; foreach ($category_array['children'] as $oldorder => $child_array) { if ($child_array['type'] == 'courseitem' or $child_array['type'] == 'categoryitem') { $child = grade_category::_fetch_course_tree_recursion($child_array, $sortorder); if (!empty($child)) { $result['children'][$sortorder] = $child; } } } foreach ($category_array['children'] as $oldorder => $child_array) { if ($child_array['type'] != 'courseitem' and $child_array['type'] != 'categoryitem') { $child = grade_category::_fetch_course_tree_recursion($child_array, $sortorder); if (!empty($child)) { $result['children'][++$sortorder] = $child; } } } } return $result; }