*/
function fetch_course_tree($courseid, $include_category_items=false) {
$course_category = grade_category::fetch_course_category($courseid);
- if (is_array($course_category)) {
- debugging("grade_category::fetch_course_category($courseid) returned an array instead of an object. Returning only the first item.");
- $course_category = reset($course_category);
- }
-
- if (is_object($course_category)) {
- $category_array = array('object'=>$course_category, 'type'=>'category', 'depth'=>1,
- 'children'=>$course_category->get_children($include_category_items));
- $sortorder = 1;
- $course_category->set_sortorder($sortorder);
- $course_category->sortorder = $sortorder;
- return grade_category::_fetch_course_tree_recursion($category_array, $sortorder);
- } else {
- debugging("grade_category::fetch_course_category($courseid) returned '$course_category'");
- return false;
- }
+ $category_array = array('object'=>$course_category, 'type'=>'category', 'depth'=>1,
+ 'children'=>$course_category->get_children($include_category_items));
+ $sortorder = 1;
+ $course_category->set_sortorder($sortorder);
+ $course_category->sortorder = $sortorder;
+ return grade_category::_fetch_course_tree_recursion($category_array, $sortorder);
}
function _fetch_course_tree_recursion($category_array, &$sortorder) {
$cats = get_records('grade_categories', 'courseid', $this->courseid);
$items = get_records('grade_items', 'courseid', $this->courseid);
- if (count($cats) == 0) {
- debugging("get_records('grade_categories', 'courseid', $this->courseid) returned nothing.");
- }
-
// init children array first
foreach ($cats as $catid=>$cat) {
$cats[$catid]->children = array();
continue;
}
$categoryid = $item->iteminstance;
- if (is_null($categoryid)) {
- debugging("Itemtype was '$item->itemtype' (item->id=$item->id), but its iteminstance was null...");
- }
} else {
$categoryid = $item->categoryid;
}
$sortorder++;
}
- if (is_null($categoryid)) {
- debugging('$categoryid was null!');
- }
-
$cats[$categoryid]->children[$sortorder] = $item;
}
// in PHP5 we could do it much better
if ($instances = grade_object::fetch_all_helper($table, $classname, $params)) {
if (count($instances) > 1) {
- // we should not tolerate any errors here - proplems might appear later
- debugging('More than one course grade_item was found for this course. Using the first one.');
- $instances = reset($instances);
+ // we should not tolerate any errors here - problems might appear later
+ error('Found more than one record in fetch() !');
}
- return $instances;
+ return reset($instances);
} else {
return false;
}
* @return boolean true if ok, array of errors if problems found (item id is used as key)
*/
function grade_regrade_final_grades($courseid, $userid=null, $updated_item=null) {
- $course_item = grade_item::fetch_course_item($courseid);
- if (!is_object($course_item)) {
- debugging("Could not instantiate the course item! grade_item::fetch_course_item($courseid) returned '$course_item'");
- }
+ $course_item = grade_item::fetch_course_item($courseid);
if ($userid) {
// one raw grade updated for one user