Browse Source

Merged PR 306 for #7153

Yannick Warnier 10 years ago
parent
commit
afa11551c4

+ 19 - 1
main/gradebook/lib/be/category.class.php

@@ -1418,7 +1418,25 @@ class Category implements GradebookItem
     }
 
     /**
-     * @return string
+     * Get all the categories from with the same given direct parent
+     * @param int $catId Category parent ID
+     * @return array Array of Category objects 
+     */
+    public function getCategories($catId)
+    {
+        $tblGradeCategories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
+        $courseInfo = api_get_course_info(api_get_course_id());
+        $courseCode = $courseInfo['code'];
+        $sql='SELECT * FROM '.$tblGradeCategories.' WHERE parent_id = '.intval($catId);
+       
+        $result = Database::query($sql);
+        $allcats = Category::create_category_objects_from_sql_result($result);
+        return $allcats;
+    }
+
+    /**
+     * Gets the type for the current object
+     * @return string 'C' to represent "Category" object type
      */
     public function get_item_type()
     {

+ 32 - 6
main/gradebook/lib/fe/displaygradebook.php

@@ -403,10 +403,20 @@ class DisplayGradebook
             $catcourse = Category::load($catobj->get_id());
             $main_weight = $catcourse[0]->get_weight();
             $scoredisplay = ScoreDisplay :: instance();
+            $categories = Category::getCategories($catcourse[0]->get_id());
             // generating the total score for a course
+            if (count($categories) > 0) {
+                foreach ($categories as $category) {
+                    $allevals = $category->get_evaluations($user_id, true);
+                    $alllinks = $category->get_links($user_id, true);
+                    $catEvalsLinks = array_merge($allevals, $alllinks);
+                }
+            }
             $allevals = $catcourse[0]->get_evaluations($user_id, true);
             $alllinks = $catcourse[0]->get_links($user_id, true);
-            $evals_links = array_merge($allevals, $alllinks);
+            $allEvalsLinks = array_merge($allevals, $alllinks);
+            //echo count($alllinks);
+            //$allEvalsLinks = array_merge($catEvalsLinks, $evalsLinks);
 
             $item_value = 0;
             $item_total = 0;
@@ -414,17 +424,33 @@ class DisplayGradebook
             $item_value_total = 0;
             $scoreinfo = null;
 
-            for ($count = 0; $count < count($evals_links); $count++) {
-                $item = $evals_links[$count];
+            for ($count = 0; $count < count($allEvalsLinks); $count++) {
+                
+                $item = $allEvalsLinks[$count];
                 $score = $item->calc_score($user_id);
                 $divide = ( ($score[1]) == 0 ) ? 1 : $score[1];
-
                 $sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()];
                 $item_value = $score[0] / $divide * $item->get_weight() * $sub_cat_percentage / $main_weight;
                 $item_value_total += $item_value;
+                $item_value_total += $score[0];
+                $item_total += $item->get_weight();
             }
-            $item_total = $main_weight;
-
+            
+            for ($count = 0; $count < count($catEvalsLinks); $count++) {
+                
+                $item = $catEvalsLinks[$count];
+                $score = $item->calc_score($user_id);
+                $divide = ( ($score[1]) == 0 ) ? 1 : $score[1];
+                $sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()];
+                //$item_value     = $score[0]/$divide;
+                $item_value = $score[0] / $divide * $item->get_weight() * $sub_cat_percentage / $main_weight;
+                $catItemValueTotal += $score[0];
+                $catItemTotal += $item->get_weight();
+            }
+            
+            //$item_total = $item->get_weight;
+            $item_value_total += $catItemValueTotal;
+            $item_total += $catItemTotal;
             $total_score = array($item_value_total, $item_total);
 
             $scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);