Minor - format code

pull/3356/head
Julio Montoya 5 years ago
parent 5c83c2b2a4
commit 781d84c883
  1. 11
      main/gradebook/lib/be/evaluation.class.php
  2. 1
      main/gradebook/lib/fe/flatviewtable.class.php
  3. 27
      main/gradebook/lib/flatview_data_generator.class.php
  4. 22
      main/gradebook/lib/scoredisplay.class.php

@ -536,6 +536,7 @@ class Evaluation implements GradebookItem
public function calc_score($stud_id = null, $type = null) public function calc_score($stud_id = null, $type = null)
{ {
$allowStats = api_get_configuration_value('allow_gradebook_stats'); $allowStats = api_get_configuration_value('allow_gradebook_stats');
if ($allowStats) { if ($allowStats) {
$evaluation = $this->entity; $evaluation = $this->entity;
if (!empty($evaluation)) { if (!empty($evaluation)) {
@ -602,10 +603,12 @@ class Evaluation implements GradebookItem
Session::write('calc_score', [$key => $results]); Session::write('calc_score', [$key => $results]);
} }
$score = 0; $score = null;
/** @var Result $res */ if (!empty($results)) {
foreach ($results as $res) { /** @var Result $res */
$score = $res->get_score(); foreach ($results as $res) {
$score = $res->get_score();
}
} }
return [$score, $this->get_max()]; return [$score, $this->get_max()];

@ -93,7 +93,6 @@ class FlatViewTable extends SortableTable
{ {
$headerName = $this->datagen->get_header_names(); $headerName = $this->datagen->get_header_names();
$total_users = $this->datagen->get_total_users_count(); $total_users = $this->datagen->get_total_users_count();
$customdisplays = ScoreDisplay::instance()->get_custom_score_display_settings(); $customdisplays = ScoreDisplay::instance()->get_custom_score_display_settings();
if (empty($customdisplays)) { if (empty($customdisplays)) {

@ -924,7 +924,6 @@ class FlatViewDataGenerator
]; ];
$item_value_total += $item_value; $item_value_total += $item_value;
$final_score += $score[0]; $final_score += $score[0];
//$final_score = ($final_score / $item_total) * 100;
} }
$total_score = [$final_score, $item_total]; $total_score = [$final_score, $item_total];
$row[] = [ $row[] = [
@ -942,21 +941,29 @@ class FlatViewDataGenerator
for ($count = 0; $count < count($this->evals_links); $count++) { for ($count = 0; $count < count($this->evals_links); $count++) {
$item = $this->evals_links[$count]; $item = $this->evals_links[$count];
$score = $item->calc_score($user[0]); $score = $item->calc_score($user[0]);
$divide = 0 == $score[1] ? 1 : $score[1]; $score_final = null;
$item_value += $score[0] / $divide * $item->get_weight(); $displayScore = null;
$item_total += $item->get_weight();
$score_denom = (0 == $score[1]) ? 1 : $score[1]; if (null !== $score) {
$score_final = ($score[0] / $score_denom) * 100; $divide = 0 == $score[1] ? 1 : $score[1];
$row[] = [ $item_value += $score[0] / $divide * $item->get_weight();
$score_final, $item_total += $item->get_weight();
trim( $score_denom = (0 == $score[1]) ? 1 : $score[1];
$score_final = ($score[0] / $score_denom) * 100;
$displayScore = trim(
$scoreDisplay->display_score( $scoreDisplay->display_score(
$score, $score,
SCORE_CUSTOM, SCORE_CUSTOM,
null, null,
true true
) )
), );
}
$row[] = [
$score_final,
$displayScore,
]; ];
} }
$total_score = [$item_value, $item_total]; $total_score = [$item_value, $item_total];

@ -302,19 +302,21 @@ class ScoreDisplay
) { ) {
$my_score = $score == 0 ? [] : $score; $my_score = $score == 0 ? [] : $score;
if ($type == SCORE_BAR) { switch ($type) {
$percentage = $my_score[0] / $my_score[1] * 100; case SCORE_BAR:
$percentage = $my_score[0] / $my_score[1] * 100;
return Display::bar_progress($percentage); return Display::bar_progress($percentage);
} break;
if ($type == SCORE_NUMERIC) { case SCORE_NUMERIC:
$percentage = $my_score[0] / $my_score[1] * 100;
return round($percentage); $percentage = $my_score[0] / $my_score[1] * 100;
}
if ($type == SCORE_SIMPLE) { return round($percentage);
return $this->format_score($my_score[0], $ignoreDecimals); break;
case SCORE_SIMPLE:
return $this->format_score($my_score[0], $ignoreDecimals);
break;
} }
if ($this->custom_enabled && isset($this->custom_display_conv)) { if ($this->custom_enabled && isset($this->custom_display_conv)) {

Loading…
Cancel
Save