//first make sure we have proper final grades - this must be done before constructing of the grade tree
grade_regrade_final_grades($courseid);
+// Perform actions
+if (!empty($target) && !empty($action) && confirm_sesskey()) {
+ grade_report_grader::process_action($target, $action);
+}
+
// Initialise the grader report object
$report = new grade_report_grader($courseid, $gpr, $context, $page, $sortitemid);
$report->user_prefs['studentsperpage'] = $perpageurl;
}
-// Perform actions
-if (!empty($target) && !empty($action) && confirm_sesskey()) {
- $report->process_action($target, $action);
-}
-
$report->load_users();
$numusers = $report->get_numusers();
$report->load_final_grades();
$eid = $element['eid'];
$object = $element['object'];
$type = $element['type'];
-
- // Load user preferences for categories
- if ($type == 'category') {
- $categoryid = $element['object']->id;
- $aggregationview = $this->get_pref('aggregationview', $categoryid);
-
-
- if ($aggregationview == GRADE_REPORT_AGGREGATION_VIEW_COMPACT) {
- $categorystate = get_user_preferences('grade_report_categorystate' . $categoryid, GRADE_CATEGORY_EXPANDED);
-
- $hideall = false;
- if (in_array($eid, $columns_to_unset)) {
- $categorystate = GRADE_CATEGORY_CONTRACTED;
- $hideall = true;
- }
-
- // Expand/Contract icon must be set appropriately
- if ($categorystate == GRADE_CATEGORY_CONTRACTED) {
- // The category is contracted: this means we only show 1 item for this category: the
- // category's aggregation item. The others must be removed from the grade_tree
- $element['colspan'] = 1;
- foreach ($element['children'] as $index => $child) {
- if ($child['type'] != 'categoryitem' OR $hideall) {
- $columns_to_unset[] = $child['eid'];
- }
- }
-
- } elseif ($categorystate == GRADE_CATEGORY_EXPANDED) {
- // The category is expanded: we only show the non-aggregated items directly descending
- // from this category. The category's grade_item must be removed from the grade_tree
- $element['colspan']--;
- foreach ($element['children'] as $index => $child) {
- if ($child['type'] == 'categoryitem') {
- $columns_to_unset[] = $child['eid'];
- }
- }
- } else {
- debugging("The category state ($categorystate) was not amongst the allowed values (0 or 1)");
- var_dump($element);
- }
- }
- } // End of category handling
+ $categorystate = @$element['categorystate'];
if (!empty($element['colspan'])) {
$colspan = 'colspan="'.$element['colspan'].'"';
}
// If object is a category, display expand/contract icon
- if ($element['type'] == 'category' && $this->get_pref('aggregationview') == GRADE_REPORT_AGGREGATION_VIEW_COMPACT) {
+ if ($element['type'] == 'category' && $this->get_pref('aggregationview', $element['object']->id) == GRADE_REPORT_AGGREGATION_VIEW_COMPACT) {
// Load language strings
$strswitch_minus = $this->get_lang_string('contract', 'grades');
$strswitch_plus = $this->get_lang_string('expand', 'grades');
*/
function fetch_course_tree($courseid, $include_category_items=false) {
$course_category = grade_category::fetch_course_category($courseid);
- $category_array = array('object'=>$course_category, 'type'=>'category', 'depth'=>1,
+ $categorystate = grade_category::get_categorystate($course_category);
+ if ($categorystate == GRADE_CATEGORY_EXPANDED) {
+ $include_category_items = false;
+ }
+
+ $category_array = array('object'=>$course_category,
+ 'type'=>'category',
+ 'depth'=>1,
+ 'categorystate' => $categorystate,
'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);
}
+ /**
+ * Checks the user preferences and returns the state of the category, for display purposes. This only
+ * applies when aggregationview is set to COMPACT.
+ * @param object $category_element
+ * @return int null, GRADE_CATEGORY_EXPANDED or GRADE_CATEGORY_CONTRACTED
+ */
+ function get_categorystate($category_element) {
+ global $CFG;
+ require_once($CFG->dirroot . '/grade/report/lib.php');
+ $aggregationview = grade_report::get_pref('aggregationview', $category_element->id);
+
+ $categorystate = null;
+ if ($aggregationview == GRADE_REPORT_AGGREGATION_VIEW_COMPACT) {
+ $categorystate = get_user_preferences('grade_report_categorystate' . $category_element->id, GRADE_CATEGORY_EXPANDED);
+ }
+ return $categorystate;
+ }
+
function _fetch_course_tree_recursion($category_array, &$sortorder) {
// update the sortorder in db if needed
if ($category_array['object']->sortorder != $sortorder) {
function _get_children_recursion($category) {
$children_array = array();
+ $categorystate = grade_category::get_categorystate($category);
+
foreach($category->children as $sortorder=>$child) {
if (array_key_exists('itemtype', $child)) {
$grade_item = new grade_item($child, false);
- if (in_array($grade_item->itemtype, array('course', 'category'))) {
- $type = $grade_item->itemtype.'item';
- $depth = $category->depth;
+ if (in_array($grade_item->itemtype, array('course', 'category'))) { // Child is a course or categoryitem
+ if ($categorystate == GRADE_CATEGORY_EXPANDED) {
+ continue;
+ } else {
+ $type = $grade_item->itemtype.'item';
+ $depth = $category->depth;
+ }
} else {
+ if ($categorystate == GRADE_CATEGORY_CONTRACTED) {
+ continue;
+ }
$type = 'item';
$depth = $category->depth; // we use this to set the same colour
}
- $children_array[$sortorder] = array('object'=>$grade_item, 'type'=>$type, 'depth'=>$depth);
+ $children_array[$sortorder] = array('object'=>$grade_item,
+ 'type'=>$type,
+ 'depth'=>$depth);
} else {
$children = grade_category::_get_children_recursion($child);
if (empty($children)) {
$children = array();
}
- $children_array[$sortorder] = array('object'=>$grade_category, 'type'=>'category', 'depth'=>$grade_category->depth, 'children'=>$children);
+ $children_array[$sortorder] = array('object'=>$grade_category,
+ 'type'=>'category',
+ 'depth'=>$grade_category->depth,
+ 'categorystate' => $categorystate,
+ 'children'=>$children);
}
}