Fix result table.

1.10.x
Julio Montoya 11 years ago
parent aa7460e095
commit 641f2b1d3b
  1. 43
      main/gradebook/lib/be/abstractlink.class.php
  2. 54
      main/gradebook/lib/be/evaluation.class.php
  3. 16
      main/gradebook/lib/fe/gradebooktable.class.php
  4. 41
      main/gradebook/lib/gradebook_data_generator.class.php

@ -61,11 +61,41 @@ abstract class AbstractLink implements GradebookItem
return $this->course_code; return $this->course_code;
} }
public function get_category_id() /**
* @return Category
*/
public function getCategory()
{ {
return $this->category; 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() public function get_date()
{ {
return $this->created_at; return $this->created_at;
@ -116,10 +146,7 @@ abstract class AbstractLink implements GradebookItem
$this->course_id = $course_info['real_id']; $this->course_id = $course_info['real_id'];
} }
public function set_category_id ($category_id)
{
$this->category = $category_id;
}
public function set_date ($date) public function set_date ($date)
{ {
@ -545,6 +572,12 @@ abstract class AbstractLink implements GradebookItem
} }
$ranking--; $ranking--;
} }
// If no ranking was detected.
if ($ranking == 0) {
return [];
}
return array($ranking, $count); return array($ranking, $count);
} }

@ -12,6 +12,7 @@ class Evaluation implements GradebookItem
private $description; private $description;
private $user_id; private $user_id;
private $course_code; private $course_code;
/** @var Category */
private $category; private $category;
private $created_at; private $created_at;
private $weight; 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 * @return int
*/ */
@ -73,11 +109,6 @@ class Evaluation implements GradebookItem
$this->sessionId = intval($sessionId); $this->sessionId = intval($sessionId);
} }
public function get_category_id()
{
return $this->category;
}
public function get_date() public function get_date()
{ {
return $this->created_at; return $this->created_at;
@ -138,11 +169,6 @@ class Evaluation implements GradebookItem
$this->course_code = $course_code; $this->course_code = $course_code;
} }
public function set_category_id($category_id)
{
$this->category = $category_id;
}
public function set_date($date) public function set_date($date)
{ {
$this->created_at = $date; $this->created_at = $date;
@ -232,13 +258,15 @@ class Evaluation implements GradebookItem
return $alleval; return $alleval;
} }
/** /**
* @param array $result * @param array $result
* @return array * @return array
*/ */
private static function create_evaluation_objects_from_sql_result($result) private static function create_evaluation_objects_from_sql_result($result)
{ {
$alleval=array(); $alleval = array();
if (Database::num_rows($result)) { if (Database::num_rows($result)) {
while ($data = Database::fetch_array($result)) { while ($data = Database::fetch_array($result)) {
$eval= new Evaluation(); $eval= new Evaluation();
@ -469,9 +497,9 @@ class Evaluation implements GradebookItem
/** /**
* Check if the given score is possible for this evaluation * 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;
} }
/** /**

@ -25,7 +25,7 @@ class GradebookTable extends SortableTable
*/ */
public function __construct($currentcat, $cats = array(), $evals = array(), $links = array(), $addparams = null) 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->evals_links = array_merge($evals, $links);
$this->currentcat = $currentcat; $this->currentcat = $currentcat;
$this->cats = $cats; $this->cats = $cats;
@ -182,7 +182,6 @@ class GradebookTable extends SortableTable
$scoredisplay = ScoreDisplay :: instance(); $scoredisplay = ScoreDisplay :: instance();
$totalResult = [0, 0]; $totalResult = [0, 0];
$totalGlobal = [0, 0];
$totalBest = [0, 0]; $totalBest = [0, 0];
$totalAverage = [0, 0]; $totalAverage = [0, 0];
@ -261,18 +260,11 @@ class GradebookTable extends SortableTable
$score = $item->calc_score(api_get_user_id()); $score = $item->calc_score(api_get_user_id());
if (!empty($score[1])) { if (!empty($score[1])) {
$categoryScoreArray = $score;
$completeScore = $scoredisplay->display_score($score, SCORE_DIV_PERCENT); $completeScore = $scoredisplay->display_score($score, SCORE_DIV_PERCENT);
$score = $score[0]/$score[1]*$item->get_weight(); $score = $score[0]/$score[1]*$item->get_weight();
$score = $scoredisplay->display_score(array($score, null), SCORE_SIMPLE); $score = $scoredisplay->display_score(array($score, null), SCORE_SIMPLE);
$categoryScore = $scoredisplay->display_score(
array($score, $mainCategoryWeight),
SCORE_DIV
);
$scoreToDisplay = Display::tip($score, $completeScore); $scoreToDisplay = Display::tip($score, $completeScore);
} else { } else {
$categoryScoreArray = [0, $item->get_weight()];
$scoreToDisplay = '-'; $scoreToDisplay = '-';
$categoryScore = null; $categoryScore = null;
} }
@ -285,8 +277,8 @@ class GradebookTable extends SortableTable
$ranking = isset($data['ranking']) ? $data['ranking'] : null; $ranking = isset($data['ranking']) ? $data['ranking'] : null;
$totalResult = [ $totalResult = [
$totalResult[0] + $data['result_score'][0], $totalResult[0] + $data['result_score_weight'][0],
$totalResult[1] + $data['result_score'][1], $totalResult[1] + $data['result_score_weight'][1],
]; ];
$totalBest = [ $totalBest = [
@ -485,6 +477,8 @@ class GradebookTable extends SortableTable
$global = null; $global = null;
$average = null; $average = null;
// Overwrite main weight
$totalResult[1] = $main_weight;
$totalResult = $scoredisplay->display_score( $totalResult = $scoredisplay->display_score(
$totalResult, $totalResult,

@ -157,6 +157,7 @@ class GradebookDataGenerator
$row[] = $resultColumn['display']; $row[] = $resultColumn['display'];
$row['result_score'] = $resultColumn['score']; $row['result_score'] = $resultColumn['score'];
$row['result_score_weight'] = $resultColumn['score_weight'];
// Best // Best
$best = $this->buildBestResultColumn($item); $best = $this->buildBestResultColumn($item);
@ -183,6 +184,7 @@ class GradebookDataGenerator
$result = $this->build_result_column($userId, $item, $ignore_score_color, true); $result = $this->build_result_column($userId, $item, $ignore_score_color, true);
$row[] = $result['display']; $row[] = $result['display'];
$row['result_score'] = $result['score']; $row['result_score'] = $result['score'];
$row['result_score_weight'] = $result['score'];
// Best // Best
$best = $this->buildBestResultColumn($item); $best = $this->buildBestResultColumn($item);
@ -241,6 +243,7 @@ class GradebookDataGenerator
/** /**
* @param GradebookItem $item * @param GradebookItem $item
*
* @return string * @return string
*/ */
private function buildAverageResultColumn(GradebookItem $item) private function buildAverageResultColumn(GradebookItem $item)
@ -256,16 +259,23 @@ class GradebookDataGenerator
/** /**
* @param GradebookItem $item * @param GradebookItem $item
* @param int $userCount
*
* @return string * @return string
*/ */
private function buildRankingColumn(GradebookItem $item, $userCount = 0) private function buildRankingColumn(GradebookItem $item, $userCount = 0)
{ {
$score = $item->calc_score(null, 'ranking'); $score = $item->calc_score(null, 'ranking');
$score[1] = $userCount; $score[1] = $userCount;
$scoreDisplay = ScoreDisplay::instance();
$scoreDisplay = null;
if (isset($score[0])) {
$scoreDisplay = ScoreDisplay::instance();
$scoreDisplay = $scoreDisplay->display_score($score, SCORE_DIV);
}
return array( return array(
'display' => $scoreDisplay->display_score($score, SCORE_DIV), 'display' => $scoreDisplay,
'score' => $score 'score' => $score
); );
} }
@ -301,23 +311,38 @@ class GradebookDataGenerator
$score, $score,
SCORE_DIV SCORE_DIV
), ),
'score' => $score 'score' => $score,
'score_weight' => $score
); );
} }
return array( return array(
'display' => get_lang('Total') . ' : '. $scoredisplay->display_score($score, $displaytype), 'display' => $scoredisplay->display_score($score, SCORE_DIV),
'score' => $score 'score' => $score,
'score_weight' => $score
); );
} else { } else {
return array( return array(
'display' => null, 'display' => null,
'score' => $score 'score' => $score,
'score_weight' => $score
); );
} }
break; break;
// evaluation and link // evaluation and link
case 'E' : case 'E' :
case 'L' : 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; /*$displaytype = SCORE_DIV_PERCENT;
if ($ignore_score_color) { if ($ignore_score_color) {
$displaytype |= SCORE_IGNORE_SPLIT; $displaytype |= SCORE_IGNORE_SPLIT;
@ -325,13 +350,15 @@ class GradebookDataGenerator
return array( return array(
'display' => $scoredisplay->display_score($score, SCORE_DIV), 'display' => $scoredisplay->display_score($score, SCORE_DIV),
'score' => $score, 'score' => $score,
'score_weight' => $scoreWeight,
); );
} }
} }
return array( return array(
'display' => null, 'display' => null,
'score' => null 'score' => null,
'score_weight' => null
); );
} }

Loading…
Cancel
Save