]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9628 Moving Basic support for compact view from report class to grade_category...
authornicolasconnault <nicolasconnault>
Wed, 25 Jul 2007 15:04:31 +0000 (15:04 +0000)
committernicolasconnault <nicolasconnault>
Wed, 25 Jul 2007 15:04:31 +0000 (15:04 +0000)
grade/report/grader/index.php
grade/report/grader/lib.php
grade/report/lib.php
lib/grade/grade_category.php

index 558fb39572d82214973950d0e987ceecd261a301..342cc782a46caaa642d607681ab5cfce687a0a96 100644 (file)
@@ -116,6 +116,11 @@ if (!is_null($toggle) && !empty($toggle_type)) {
 //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);
 
@@ -129,11 +134,6 @@ if ($perpageurl) {
     $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();
index c2af344834ae33bd1925e7d3ef9b255779046717..1e106835ee21319283bba641a4bcdedebe795815 100644 (file)
@@ -415,48 +415,7 @@ class grade_report_grader extends grade_report {
                 $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'].'"';
@@ -936,7 +895,7 @@ class grade_report_grader extends grade_report {
         }
 
         // 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');
index da008d5b0acd22d6a3afa99d1d747e7f1efce3a5..171e7aef35d9b0a968476b3e2be730bef4a77b52 100755 (executable)
@@ -135,7 +135,7 @@ class grade_report {
 
         $retval = null;
 
-        if (!isset($this)) {
+        if (!isset($this) OR get_class($this) != 'grade_report') {
             if (!empty($objectid)) {
                 $retval = get_user_preferences($fullprefname . $objectid, grade_report::get_pref($pref));
             } else {
index 6f4a51285155f59e11181a21e21864a11feee5a2..6eac93f4faa4f87f9edc35f74251167d7dab76ef 100644 (file)
@@ -628,14 +628,41 @@ class grade_category extends grade_object {
      */
     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) {
@@ -742,17 +769,28 @@ class grade_category extends grade_object {
     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);
@@ -760,7 +798,11 @@ class grade_category extends grade_object {
                 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);
             }
         }