diff --git a/main/gradebook/lib/be/abstractlink.class.php b/main/gradebook/lib/be/abstractlink.class.php index 96ceff2c53..acb546f8d0 100755 --- a/main/gradebook/lib/be/abstractlink.class.php +++ b/main/gradebook/lib/be/abstractlink.class.php @@ -61,11 +61,41 @@ abstract class AbstractLink implements GradebookItem return $this->course_code; } - public function get_category_id() + /** + * @return Category + */ + public function getCategory() { return $this->category; } + /** + * @param Category $category + */ + public function setCategory($category) + { + $this->category = $category; + } + + /** + * @return int + */ + public function get_category_id() + { + return $this->category->get_id(); + } + + /** + * @param int $category_id + */ + public function set_category_id($category_id) + { + $categories = Category::load($category_id); + if (isset($categories[0])) { + $this->setCategory($categories[0]); + } + } + public function get_date() { return $this->created_at; @@ -116,10 +146,7 @@ abstract class AbstractLink implements GradebookItem $this->course_id = $course_info['real_id']; } - public function set_category_id ($category_id) - { - $this->category = $category_id; - } + public function set_date ($date) { @@ -545,6 +572,12 @@ abstract class AbstractLink implements GradebookItem } $ranking--; } + + // If no ranking was detected. + if ($ranking == 0) { + return []; + } + return array($ranking, $count); } diff --git a/main/gradebook/lib/be/evaluation.class.php b/main/gradebook/lib/be/evaluation.class.php index bb3585243b..9b4298a7bb 100755 --- a/main/gradebook/lib/be/evaluation.class.php +++ b/main/gradebook/lib/be/evaluation.class.php @@ -12,6 +12,7 @@ class Evaluation implements GradebookItem private $description; private $user_id; private $course_code; + /** @var Category */ private $category; private $created_at; private $weight; @@ -26,6 +27,41 @@ class Evaluation implements GradebookItem { } + /** + * @return Category + */ + public function getCategory() + { + return $this->category; + } + + /** + * @param Category $category + */ + public function setCategory($category) + { + $this->category = $category; + } + + /** + * @return int + */ + public function get_category_id() + { + return $this->category->get_id(); + } + + /** + * @param int $category_id + */ + public function set_category_id($category_id) + { + $categories = Category::load($category_id); + if (isset($categories[0])) { + $this->setCategory($categories[0]); + } + } + /** * @return int */ @@ -73,11 +109,6 @@ class Evaluation implements GradebookItem $this->sessionId = intval($sessionId); } - public function get_category_id() - { - return $this->category; - } - public function get_date() { return $this->created_at; @@ -138,11 +169,6 @@ class Evaluation implements GradebookItem $this->course_code = $course_code; } - public function set_category_id($category_id) - { - $this->category = $category_id; - } - public function set_date($date) { $this->created_at = $date; @@ -232,13 +258,15 @@ class Evaluation implements GradebookItem return $alleval; } + + /** * @param array $result * @return array */ private static function create_evaluation_objects_from_sql_result($result) { - $alleval=array(); + $alleval = array(); if (Database::num_rows($result)) { while ($data = Database::fetch_array($result)) { $eval= new Evaluation(); @@ -469,9 +497,9 @@ class Evaluation implements GradebookItem /** * Check if the given score is possible for this evaluation */ - public function is_valid_score ($score) + public function is_valid_score($score) { - return (is_numeric($score) && $score >= 0 && $score <= $this->eval_max); + return is_numeric($score) && $score >= 0 && $score <= $this->eval_max; } /** diff --git a/main/gradebook/lib/fe/gradebooktable.class.php b/main/gradebook/lib/fe/gradebooktable.class.php index accf6e7cd3..37e20ecf08 100755 --- a/main/gradebook/lib/fe/gradebooktable.class.php +++ b/main/gradebook/lib/fe/gradebooktable.class.php @@ -25,7 +25,7 @@ class GradebookTable extends SortableTable */ public function __construct($currentcat, $cats = array(), $evals = array(), $links = array(), $addparams = null) { - parent::__construct('gradebooklist', null, null, (api_is_allowed_to_edit()?1:0)); + parent::__construct('gradebooklist', null, null, api_is_allowed_to_edit() ? 1 : 0); $this->evals_links = array_merge($evals, $links); $this->currentcat = $currentcat; $this->cats = $cats; @@ -182,7 +182,6 @@ class GradebookTable extends SortableTable $scoredisplay = ScoreDisplay :: instance(); $totalResult = [0, 0]; - $totalGlobal = [0, 0]; $totalBest = [0, 0]; $totalAverage = [0, 0]; @@ -261,18 +260,11 @@ class GradebookTable extends SortableTable $score = $item->calc_score(api_get_user_id()); if (!empty($score[1])) { - $categoryScoreArray = $score; $completeScore = $scoredisplay->display_score($score, SCORE_DIV_PERCENT); $score = $score[0]/$score[1]*$item->get_weight(); $score = $scoredisplay->display_score(array($score, null), SCORE_SIMPLE); - - $categoryScore = $scoredisplay->display_score( - array($score, $mainCategoryWeight), - SCORE_DIV - ); $scoreToDisplay = Display::tip($score, $completeScore); } else { - $categoryScoreArray = [0, $item->get_weight()]; $scoreToDisplay = '-'; $categoryScore = null; } @@ -285,8 +277,8 @@ class GradebookTable extends SortableTable $ranking = isset($data['ranking']) ? $data['ranking'] : null; $totalResult = [ - $totalResult[0] + $data['result_score'][0], - $totalResult[1] + $data['result_score'][1], + $totalResult[0] + $data['result_score_weight'][0], + $totalResult[1] + $data['result_score_weight'][1], ]; $totalBest = [ @@ -485,6 +477,8 @@ class GradebookTable extends SortableTable $global = null; $average = null; + // Overwrite main weight + $totalResult[1] = $main_weight; $totalResult = $scoredisplay->display_score( $totalResult, diff --git a/main/gradebook/lib/gradebook_data_generator.class.php b/main/gradebook/lib/gradebook_data_generator.class.php index 1e4b670298..a80e27fcea 100755 --- a/main/gradebook/lib/gradebook_data_generator.class.php +++ b/main/gradebook/lib/gradebook_data_generator.class.php @@ -157,6 +157,7 @@ class GradebookDataGenerator $row[] = $resultColumn['display']; $row['result_score'] = $resultColumn['score']; + $row['result_score_weight'] = $resultColumn['score_weight']; // Best $best = $this->buildBestResultColumn($item); @@ -183,6 +184,7 @@ class GradebookDataGenerator $result = $this->build_result_column($userId, $item, $ignore_score_color, true); $row[] = $result['display']; $row['result_score'] = $result['score']; + $row['result_score_weight'] = $result['score']; // Best $best = $this->buildBestResultColumn($item); @@ -241,6 +243,7 @@ class GradebookDataGenerator /** * @param GradebookItem $item + * * @return string */ private function buildAverageResultColumn(GradebookItem $item) @@ -256,16 +259,23 @@ class GradebookDataGenerator /** * @param GradebookItem $item + * @param int $userCount + * * @return string */ private function buildRankingColumn(GradebookItem $item, $userCount = 0) { $score = $item->calc_score(null, 'ranking'); $score[1] = $userCount; - $scoreDisplay = ScoreDisplay::instance(); + + $scoreDisplay = null; + if (isset($score[0])) { + $scoreDisplay = ScoreDisplay::instance(); + $scoreDisplay = $scoreDisplay->display_score($score, SCORE_DIV); + } return array( - 'display' => $scoreDisplay->display_score($score, SCORE_DIV), + 'display' => $scoreDisplay, 'score' => $score ); } @@ -301,23 +311,38 @@ class GradebookDataGenerator $score, SCORE_DIV ), - 'score' => $score + 'score' => $score, + 'score_weight' => $score ); } + return array( - 'display' => get_lang('Total') . ' : '. $scoredisplay->display_score($score, $displaytype), - 'score' => $score + 'display' => $scoredisplay->display_score($score, SCORE_DIV), + 'score' => $score, + 'score_weight' => $score ); } else { return array( 'display' => null, - 'score' => $score + 'score' => $score, + 'score_weight' => $score ); } break; // evaluation and link case 'E' : case 'L' : + /** @var Category $category */ + $category = $item->getCategory(); + $parentId = $category->get_parent_id(); + $scoreWeight = []; + + if ($parentId == 0) { + $scoreWeight = [ + $score[0] / $score[1] * $item->get_weight(), + $item->get_weight() + ]; + } /*$displaytype = SCORE_DIV_PERCENT; if ($ignore_score_color) { $displaytype |= SCORE_IGNORE_SPLIT; @@ -325,13 +350,15 @@ class GradebookDataGenerator return array( 'display' => $scoredisplay->display_score($score, SCORE_DIV), 'score' => $score, + 'score_weight' => $scoreWeight, ); } } return array( 'display' => null, - 'score' => null + 'score' => null, + 'score_weight' => null ); }