From 7180de415e5795ce40db27926e35a5a8d9b4a8ff Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 23 May 2014 09:41:17 -0400 Subject: [PATCH] Fixe for showing result in header into gradebook cateboris -refs #7153 --- main/gradebook/lib/be/category.class.php | 12 ++++++- main/gradebook/lib/fe/displaygradebook.php | 40 +++++++++++++++++----- 2 files changed, 43 insertions(+), 9 deletions(-) mode change 100755 => 100644 main/gradebook/lib/be/category.class.php mode change 100755 => 100644 main/gradebook/lib/fe/displaygradebook.php diff --git a/main/gradebook/lib/be/category.class.php b/main/gradebook/lib/be/category.class.php old mode 100755 new mode 100644 index 71d77bf4e2..6d8c080647 --- a/main/gradebook/lib/be/category.class.php +++ b/main/gradebook/lib/be/category.class.php @@ -1378,7 +1378,17 @@ class Category implements GradebookItem return $links; } - + 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; + } public function get_item_type() { return 'C'; diff --git a/main/gradebook/lib/fe/displaygradebook.php b/main/gradebook/lib/fe/displaygradebook.php old mode 100755 new mode 100644 index 63faabec34..114765a777 --- a/main/gradebook/lib/fe/displaygradebook.php +++ b/main/gradebook/lib/fe/displaygradebook.php @@ -391,11 +391,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; @@ -403,18 +412,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_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);