From 1eb05d980c5acff46e877707889cd3cd2a25d1be Mon Sep 17 00:00:00 2001 From: skodak Date: Fri, 3 Aug 2007 08:41:20 +0000 Subject: [PATCH] improved aggregation - items without value (none + text) are not aggregated; faster regrading of categroies with no grades; lang typo fixed --- lang/en_utf8/grades.php | 2 +- lib/grade/grade_item.php | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lang/en_utf8/grades.php b/lang/en_utf8/grades.php index 6a97320fa4..af9ef0c85c 100644 --- a/lang/en_utf8/grades.php +++ b/lang/en_utf8/grades.php @@ -19,7 +19,7 @@ $string['aggregateminall'] = 'Smallest grade of all grades'; $string['aggregatemingraded'] = 'Smallest grade of non-empty grades'; $string['aggregatemaxall'] = 'Highest grade of all grades'; $string['aggregatemaxgraded'] = 'Highest grade of non-empty grades'; -$string['aggregatemodeall'] = 'Mode of non-empty grades of all grades'; +$string['aggregatemodeall'] = 'Mode of all grades'; $string['aggregatemodegraded'] = 'Mode of non-empty grades'; $string['aggregateweightedmeanall'] = 'Weighted mean of all grades'; $string['aggregateweightedmeangraded'] = 'Weighted mean of non-empty grades'; diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index 106fb352f3..614e0adb29 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -1125,16 +1125,23 @@ class grade_item extends grade_object { } } else if ($grade_category = $this->load_item_category()) { + //only items with numeric or scale values can be aggregated + if ($this->gradetype != GRADE_TYPE_VALUE and $this->gradetype != GRADE_TYPE_SCALE) { + return array(); + } + $sql = "SELECT gi.id FROM {$CFG->prefix}grade_items gi - WHERE gi.categoryid ={$grade_category->id} + WHERE gi.categoryid = {$grade_category->id} + AND (gi.gradetype = ".GRADE_TYPE_VALUE." OR gi.gradetype = ".GRADE_TYPE_SCALE.") UNION SELECT gi.id FROM {$CFG->prefix}grade_items gi, {$CFG->prefix}grade_categories gc WHERE (gi.itemtype = 'category' OR gi.itemtype = 'course') AND gi.iteminstance=gc.id - AND gc.parent = {$grade_category->id}"; + AND gc.parent = {$grade_category->id} + AND (gi.gradetype = ".GRADE_TYPE_VALUE." OR gi.gradetype = ".GRADE_TYPE_SCALE.")"; if ($children = get_records_sql($sql)) { return array_keys($children); -- 2.39.5