Admin: Add config gradebook_pdf_export_settings BT#17899

Gradebook student pdf export settings hide score weight column.

Admin: Add config gradebook_use_exercise_score_settings_in_total

Use exercise score settings in score category totals.

Remove decimals. Example: 100.00 replaced to 100
pull/3586/head
Julio Montoya 5 years ago
parent bc56439bc2
commit 87d370bc26
  1. 179
      main/gradebook/lib/fe/gradebooktable.class.php
  2. 120
      main/gradebook/lib/gradebook_data_generator.class.php
  3. 110
      main/gradebook/lib/scoredisplay.class.php
  4. 4
      main/inc/lib/exercise.lib.php
  5. 8
      main/install/configuration.dist.php

@ -79,6 +79,7 @@ class GradebookTable extends SortableTable
$this->cats = $cats;
$this->loadStats = $loadStats;
$this->datagen = new GradebookDataGenerator($cats, $evals, $links);
$this->datagen->exportToPdf = $this->exportToPdf;
$this->datagen->preLoadDataKey = $this->getPreloadDataKey();
$this->datagen->hidePercentage = api_get_configuration_value('hide_gradebook_percentage_user_result');
@ -99,19 +100,24 @@ class GradebookTable extends SortableTable
$this->set_header($column++, get_lang('Type'), '', 'width="35px"');
$this->set_header($column++, get_lang('Name'), false);
if (false == $this->exportToPdf) {
$this->set_header($column++, get_lang('Description'), false);
}
$model = ExerciseLib::getCourseScoreModel();
$this->set_header(
$column++,
get_lang('Weight'),
'',
'width="100px"'
);
$settings = api_get_configuration_value('gradebook_pdf_export_settings');
$showWeight = true;
if ($this->exportToPdf && isset($settings['hide_score_weight']) && $settings['hide_score_weight']) {
$showWeight = false;
}
if ($showWeight) {
$this->set_header(
$column++,
get_lang('Weight'),
'',
'width="100px"'
);
}
if (!$this->teacherView) {
$this->set_header($column++, get_lang('Result'), false);
@ -220,7 +226,6 @@ class GradebookTable extends SortableTable
// Average
$average = $this->datagen->buildAverageResultColumn($item);
$defaultData[$item->get_id()]['average'] = $average;
// Ranking
/*if (!empty($this->studentList)) {
$invalidateRanking = true;
@ -374,8 +379,6 @@ class GradebookTable extends SortableTable
$total_categories_weight = 0;
$scoredisplay = ScoreDisplay::instance();
$totalUserResult = [0, 0];
$totalBest = [0, 0];
$totalAverage = [0, 0];
@ -388,10 +391,15 @@ class GradebookTable extends SortableTable
$userExerciseScoreInCategory = api_get_configuration_value(
'gradebook_use_exercise_score_settings_in_categories'
);
$useExerciseScoreInTotal = api_get_configuration_value('gradebook_use_exercise_score_settings_in_total');
$course_code = api_get_course_id();
$session_id = api_get_session_id();
$defaultData = Session::read($this->getPreloadDataKey());
$settings = api_get_configuration_value('gradebook_pdf_export_settings');
$showWeight = true;
if ($this->exportToPdf && isset($settings['hide_score_weight']) && $settings['hide_score_weight']) {
$showWeight = false;
}
// Categories.
if (!empty($data_array)) {
@ -400,7 +408,6 @@ class GradebookTable extends SortableTable
$row = [];
/** @var AbstractLink $item */
$item = $data[0];
// If the item is invisible, wrap it in a span with class invisible
$invisibility_span_open = $isAllowedToEdit && $item->is_visible() == '0' ? '<span class="text-muted">' : '';
$invisibility_span_close = $isAllowedToEdit && $item->is_visible() == '0' ? '</span>' : '';
@ -416,7 +423,7 @@ class GradebookTable extends SortableTable
$row[] = $this->build_type_column($item);
// Name.
if (get_class($item) === 'Category') {
if ('Category' === get_class($item)) {
$row[] = $invisibility_span_open.'<strong>'.$item->get_name().'</strong>'.$invisibility_span_close;
$main_categories[$item->get_id()]['name'] = $item->get_name();
} else {
@ -445,16 +452,17 @@ class GradebookTable extends SortableTable
true
);
if ($this->teacherView) {
$row[] = $invisibility_span_open.
Display::tag('p', $weight, ['class' => 'score']).
$invisibility_span_close;
} else {
$row[] = $invisibility_span_open.$weight.$invisibility_span_close;
if ($showWeight) {
if ($this->teacherView) {
$row[] = $invisibility_span_open.
Display::tag('p', $weight, ['class' => 'score']).
$invisibility_span_close;
} else {
$row[] = $invisibility_span_open.$weight.$invisibility_span_close;
}
}
$category_weight = $item->get_weight();
if ($this->teacherView) {
$weight_total_links += $data[3];
}
@ -467,15 +475,13 @@ class GradebookTable extends SortableTable
$row[] = $this->build_edit_column($item);
}
} else {
$score = $item->calc_score($this->userId);
/*$score = $item->calc_score($this->userId);
if (!empty($score[1])) {
$completeScore = $scoredisplay->display_score($score, SCORE_DIV_PERCENT);
$score = $score[0] / $score[1] * $item->get_weight();
$score = $scoredisplay->display_score([$score, null], SCORE_SIMPLE);
} else {
$categoryScore = null;
}
}*/
// Students get the results and certificates columns
$value_data = isset($data[4]) ? $data[4] : null;
$best = isset($data['best']) ? $data['best'] : null;
@ -492,14 +498,16 @@ class GradebookTable extends SortableTable
$scoredisplay->format_score($totalBest[0] + $data['best_score'][0]),
$scoredisplay->format_score($totalBest[1] + $data['best_score'][1]),
];
$totalAverage = [
$data['average_score'][0],
$data['average_score'][1],
];
$totalAverage = [0, 0];
if (isset($data['average_score']) && !empty($data['average_score'])) {
$totalAverage = [
$data['average_score'][0],
$data['average_score'][1],
];
}
}
// Student result
// Score
if (empty($model)) {
$row[] = $value_data;
} else {
@ -527,8 +535,12 @@ class GradebookTable extends SortableTable
$data['my_result_no_float'][0] = $result['score'];
}
$totalResultAverageValue = strip_tags($scoredisplay->display_score($totalResult, $mode));
$totalAverageValue = strip_tags($scoredisplay->display_score($totalAverage, $mode));
$totalResultAverageValue = strip_tags(
$scoredisplay->display_score($totalResult, $mode, null, false, false, true)
);
$totalAverageValue = strip_tags(
$scoredisplay->display_score($totalAverage, $mode, null, false, false, true)
);
$this->dataForGraph['my_result'][] = floatval($totalResultAverageValue);
$this->dataForGraph['average'][] = floatval($totalAverageValue);
@ -581,6 +593,7 @@ class GradebookTable extends SortableTable
$alllink = $subCategory->get_links($this->userId);
$sub_cat_info = new GradebookDataGenerator($allcat, $alleval, $alllink);
$sub_cat_info->exportToPdf = $this->exportToPdf;
$sub_cat_info->preLoadDataKey = $this->getPreloadDataKey();
$sub_cat_info->userId = $user_id;
$data_array2 = $sub_cat_info->get_data(
@ -596,8 +609,7 @@ class GradebookTable extends SortableTable
foreach ($data_array2 as $data) {
$row = [];
$item = $data[0];
//if the item is invisible, wrap it in a span with class invisible
// if the item is invisible, wrap it in a span with class invisible
$invisibility_span_open = $isAllowedToEdit && $item->is_visible() == '0' ? '<span class="text-muted">' : '';
$invisibility_span_close = $isAllowedToEdit && $item->is_visible() == '0' ? '</span>' : '';
@ -614,7 +626,6 @@ class GradebookTable extends SortableTable
// Type
$row[] = $this->build_type_column($item, ['style' => 'padding-left:5px']);
// Name.
$row[] = $invisibility_span_open.'&nbsp;&nbsp;&nbsp; '.
$this->build_name_link($item, $type, 4).$invisibility_span_close;
@ -628,7 +639,9 @@ class GradebookTable extends SortableTable
$total_weight += $weight;
// Weight
$row[] = $invisibility_span_open.$weight.$invisibility_span_close;
if ($showWeight) {
$row[] = $invisibility_span_open.$weight.$invisibility_span_close;
}
// Admins get an edit column.
if (api_is_allowed_to_edit(null, true) &&
@ -645,25 +658,23 @@ class GradebookTable extends SortableTable
} else {
// Students get the results and certificates columns
$eval_n_links = array_merge($alleval, $alllink);
if (count($eval_n_links) > 0) {
$value_data = isset($data[4]) ? $data[4] : null;
if (!is_null($value_data)) {
// Result
$row[] = $value_data;
$best = isset($data['best']) ? $data['best'] : null;
$average = isset($data['average']) ? $data['average'] : null;
$ranking = isset($data['ranking']) ? $data['ranking'] : null;
if (empty($model)) {
// Ranking
if (in_array(1, $this->loadStats)) {
// Ranking
$row[] = $ranking;
}
// Best
if (in_array(2, $this->loadStats)) {
// Best
$row[] = $best;
}
@ -776,8 +787,16 @@ class GradebookTable extends SortableTable
} else {
$totalResult = $scoredisplay->display_score(
$totalResult,
SCORE_DIV
SCORE_DIV,
null,
false,
false,
true
);
if ($useExerciseScoreInTotal) {
$totalResult = ExerciseLib::show_score($myTotal, $main_weight, false);
}
}
$row = [
@ -789,7 +808,10 @@ class GradebookTable extends SortableTable
$row[] = null;
}
$row[] = $main_weight;
if ($showWeight) {
$row[] = $main_weight;
}
$row[] = $totalResult;
$categoryId = $main_cat[0]->get_id();
@ -826,13 +848,18 @@ class GradebookTable extends SortableTable
}
$totalRanking = AbstractLink::getCurrentUserRanking($user_id, $totalRanking);
$totalRanking = $scoredisplay->display_score(
$totalRanking,
SCORE_DIV,
SCORE_BOTH,
true,
true
);
if ($useExerciseScoreInTotal) {
$totalRanking = ExerciseLib::show_score($totalRanking[0], $totalRanking[1], false);
} else {
$totalRanking = $scoredisplay->display_score(
$totalRanking,
SCORE_DIV,
SCORE_BOTH,
true,
true,
true
);
}
if ($invalidateRanking) {
$totalRanking = null;
@ -848,12 +875,25 @@ class GradebookTable extends SortableTable
$totalBest[1] = $main_weight;
$defaultData[$categoryId]['best'] = $totalBest;
}
$totalBest = $scoredisplay->display_score(
$totalBest,
SCORE_DIV,
SCORE_BOTH,
true
);
if ($useExerciseScoreInTotal) {
if (isset($totalBest['score'])) {
$totalBestScore = $totalBest['score'];
} else {
$totalBestScore = $totalBest;
}
$totalBest = ExerciseLib::show_score($totalBestScore[0], $totalBestScore[1], true);
} else {
$totalBest = $scoredisplay->display_score(
$totalBest,
SCORE_DIV,
SCORE_BOTH,
true,
false,
true
);
}
$row[] = $totalBest;
}
@ -867,12 +907,24 @@ class GradebookTable extends SortableTable
$defaultData[$categoryId]['average'] = $totalBest;
}
$totalAverage = $scoredisplay->display_score(
$totalAverage,
SCORE_DIV,
SCORE_BOTH,
true
);
if ($useExerciseScoreInTotal) {
if (isset($totalAverage['score'])) {
$totalAverageScore = $totalAverage['score'];
} else {
$totalAverageScore = $totalAverage;
}
$totalAverage = ExerciseLib::show_score($totalAverageScore[0], $totalAverageScore[1], true);
} else {
$totalAverage = $scoredisplay->display_score(
$totalAverage,
SCORE_DIV,
SCORE_BOTH,
true,
false,
true
);
}
$row[] = $totalAverage;
}
@ -905,7 +957,8 @@ class GradebookTable extends SortableTable
) {
$warning_message = sprintf(get_lang('TotalWeightMustBeX'), $weight_category);
$modify_icons =
'<a href="gradebook_edit_cat.php?editcat='.$id_cat.'&cidReq='.$course_code.'&id_session='.api_get_session_id().'">'.
'<a
href="gradebook_edit_cat.php?editcat='.$id_cat.'&cidReq='.$course_code.'&id_session='.api_get_session_id().'">'.
Display::return_icon('edit.png', $warning_message, [], ICON_SIZE_SMALL).'</a>';
$warning_message .= $modify_icons;
echo Display::return_message($warning_message, 'warning', false);

@ -28,6 +28,7 @@ class GradebookDataGenerator
public $items;
public $preLoadDataKey;
private $evals_links;
public $exportToPdf;
/**
* @param array $cats
@ -39,6 +40,7 @@ class GradebookDataGenerator
$allcats = isset($cats) ? $cats : [];
$allevals = isset($evals) ? $evals : [];
$alllinks = isset($links) ? $links : [];
$this->exportToPdf = false;
// if we are in the root category and if there are sub categories
// display only links depending of the root category and not link that belongs
@ -108,8 +110,6 @@ class GradebookDataGenerator
usort($allitems, ['GradebookDataGenerator', 'sort_by_name']);
$userId = $this->userId;
// Get selected items
$visibleItems = array_slice($allitems, $start, $count);
$userCount = !empty($studentList) ? count($studentList) : 0;
@ -118,8 +118,8 @@ class GradebookDataGenerator
$allowStats = api_get_configuration_value('allow_gradebook_stats');
$scoreDisplay = ScoreDisplay::instance();
$defaultData = Session::read($this->preLoadDataKey);
$model = ExerciseLib::getCourseScoreModel();
$useExerciseScoreInTotal = api_get_configuration_value('gradebook_use_exercise_score_settings_in_total');
/** @var GradebookItem $item */
foreach ($visibleItems as $item) {
@ -140,9 +140,9 @@ class GradebookDataGenerator
$resultColumn = $this->build_result_column(
$userId,
$item,
$ignore_score_color
$ignore_score_color,
false
);
$row[] = $resultColumn['display'];
$row['result_score'] = $resultColumn['score'];
$row['result_score_weight'] = $resultColumn['score_weight'];
@ -280,11 +280,9 @@ class GradebookDataGenerator
if (!empty($links)) {
foreach ($links as $link) {
$link->setStudentList($studentList);
if ($session_id) {
$link->set_session_id($session_id);
}
$linkres = $link->calc_score($user['user_id'], null);
if (!empty($linkres) && 0 != $link->get_weight()) {
$linkweight = $link->get_weight();
@ -333,7 +331,8 @@ class GradebookDataGenerator
$userId,
$item,
$ignore_score_color,
true
true,
$useExerciseScoreInTotal
);
$row[] = $result['display'];
$row['result_score'] = $result['score'];
@ -343,21 +342,29 @@ class GradebookDataGenerator
// Best
if (isset($defaultData[$item->get_id()]) && isset($defaultData[$item->get_id()]['best'])) {
$best = $defaultData[$item->get_id()]['best'];
if ($useExerciseScoreInTotal) {
$bestScore = $best['score'];
$best['display'] = ExerciseLib::show_score($bestScore[0], $bestScore[1], true);
} else {
$best = $defaultData[$item->get_id()]['best'];
}
} else {
$best = $this->buildBestResultColumn($item);
$best = $this->buildBestResultColumn($item, $useExerciseScoreInTotal);
}
$row['best'] = $best['display'];
$row['best_score'] = $best['score'];
$rankingStudentList = [];
$invalidateResults = true;
// Average
if (isset($defaultData[$item->get_id()]) && isset($defaultData[$item->get_id()]['average'])) {
$average = $defaultData[$item->get_id()]['average'];
if ($useExerciseScoreInTotal) {
$averageScore = $average['score'];
$average['display'] = ExerciseLib::show_score($averageScore[0], $averageScore[1], true);
}
} else {
$average = $this->buildAverageResultColumn($item);
$average = $this->buildAverageResultColumn($item, $useExerciseScoreInTotal);
}
$row['average'] = $average['display'];
$row['average_score'] = $average['score'];
@ -391,6 +398,7 @@ class GradebookDataGenerator
SCORE_DIV,
SCORE_BOTH,
true,
true,
true
);
@ -418,7 +426,8 @@ class GradebookDataGenerator
{
if (is_a($item, 'Category')) {
if ($item->is_certificate_available(api_get_user_id())) {
$link = '<a href="'.Category::getUrl().'export_certificate=1&cat='.$item->get_id().'&user='.api_get_user_id().'">'.
$link = '<a
href="'.Category::getUrl().'export_certificate=1&cat='.$item->get_id().'&user='.api_get_user_id().'">'.
get_lang('Certificate').'</a>';
return $link;
@ -460,9 +469,9 @@ class GradebookDataGenerator
{
if ($item1->get_item_type() == $item2->get_item_type()) {
return $this->sort_by_name($item1, $item2);
} else {
return $item1->get_item_type() < $item2->get_item_type() ? -1 : 1;
}
return $item1->get_item_type() < $item2->get_item_type() ? -1 : 1;
}
/**
@ -491,9 +500,9 @@ class GradebookDataGenerator
{
if ($item1->get_weight() == $item2->get_weight()) {
return $this->sort_by_name($item1, $item2);
} else {
return $item1->get_weight() < $item2->get_weight() ? -1 : 1;
}
return $item1->get_weight() < $item2->get_weight() ? -1 : 1;
}
/**
@ -523,9 +532,9 @@ class GradebookDataGenerator
if ($timestamp1 == $timestamp2) {
return $this->sort_by_name($item1, $item2);
} else {
return $timestamp1 < $timestamp2 ? -1 : 1;
}
return $timestamp1 < $timestamp2 ? -1 : 1;
}
/**
@ -533,7 +542,7 @@ class GradebookDataGenerator
*
* @return array
*/
public function buildBestResultColumn(GradebookItem $item)
public function buildBestResultColumn(GradebookItem $item, $userExerciseSettings = false)
{
$score = $item->calc_score(
null,
@ -559,11 +568,25 @@ class GradebookDataGenerator
$score,
$scoreMode,
SCORE_BOTH,
true,
false,
true
);
$type = $item->get_item_type();
if ('L' === $type && 'ExerciseLink' === get_class($item)) {
$display = ExerciseLib::show_score($score[0], $score[1], false);
$display = ExerciseLib::show_score(
$score[0],
$score[1],
false
);
}
if ($userExerciseSettings) {
$display = ExerciseLib::show_score(
$score[0],
$score[1],
true
);
}
return [
@ -575,7 +598,7 @@ class GradebookDataGenerator
/**
* @return array
*/
public function buildAverageResultColumn(GradebookItem $item)
public function buildAverageResultColumn(GradebookItem $item, $userExerciseSettings = false)
{
$score = $item->calc_score(null, 'average');
@ -597,6 +620,8 @@ class GradebookDataGenerator
$score,
$scoreMode,
SCORE_BOTH,
true,
false,
true
);
$type = $item->get_item_type();
@ -606,6 +631,14 @@ class GradebookDataGenerator
$result = ExerciseLib::convertScoreToPlatformSetting($score[0], $score[1]);
$score[0] = $result['score'];
$score[1] = $result['weight'];
} else {
if ($userExerciseSettings) {
$display = ExerciseLib::show_score(
$score[0],
$score[1],
true
);
}
}
return [
@ -632,6 +665,7 @@ class GradebookDataGenerator
SCORE_DIV,
SCORE_BOTH,
false,
true,
true
);
}
@ -653,23 +687,32 @@ class GradebookDataGenerator
$userId,
$item,
$ignore_score_color,
$forceSimpleResult = false
$forceSimpleResult = false,
$useExerciseScoreInTotal = false
) {
$scoreDisplay = ScoreDisplay::instance();
$score = $item->calc_score($userId);
$model = ExerciseLib::getCourseScoreModel();
if (!empty($score)) {
switch ($item->get_item_type()) {
// category
case 'C':
if (null != $score) {
if (empty($model)) {
return [
'display' => $scoreDisplay->display_score(
if ($useExerciseScoreInTotal) {
$display = ExerciseLib::show_score($score[0], $score[1], false);
} else {
$display = $scoreDisplay->display_score(
$score,
SCORE_DIV
),
SCORE_DIV,
null,
false,
false,
true
);
}
return [
'display' => $display,
'score' => $score,
'score_weight' => $score,
];
@ -704,15 +747,26 @@ class GradebookDataGenerator
if (empty($model)) {
$display = $scoreDisplay->display_score(
$score,
SCORE_DIV_PERCENT_WITH_CUSTOM
SCORE_DIV_PERCENT_WITH_CUSTOM,
null,
false,
false,
true
);
$type = $item->get_item_type();
if ('L' == $type && 'ExerciseLink' == get_class($item)) {
if ('L' === $type && 'ExerciseLink' === get_class($item)) {
$display = ExerciseLib::show_score(
$score[0],
$score[1],
false
false,
true,
false,
false,
null,
null,
false,
true
);
}
} else {
@ -751,9 +805,9 @@ class GradebookDataGenerator
} else {
if (is_int($date)) {
return api_convert_and_format_date($date);
} else {
return api_format_date($date);
}
return api_format_date($date);
}
}
}

@ -265,19 +265,53 @@ class ScoreDisplay
* @param bool $ignoreDecimals
* @param string $decimalSeparator
* @param string $thousandSeparator
* @param bool $removeEmptyDecimals Converts 100.00 to 100, 53.00 to 53
*
* @return float the score formatted
*/
public function format_score($score, $ignoreDecimals = false, $decimalSeparator = '.', $thousandSeparator = ',')
{
public function format_score(
$score,
$ignoreDecimals = false,
$decimalSeparator = '.',
$thousandSeparator = ',',
$removeEmptyDecimals = false
) {
$decimals = $this->get_number_decimals();
if ($ignoreDecimals) {
$decimals = 0;
}
if ($removeEmptyDecimals) {
if ($score && self::hasEmptyDecimals($score)) {
$score = round($score);
$decimals = 0;
}
}
return api_number_format($score, $decimals, $decimalSeparator, $thousandSeparator);
}
public static function hasEmptyDecimals($score)
{
$hasEmptyDecimals = false;
if (is_float($score)) {
$check = fmod($score, 1);
if (0 === bccomp(0, $check)) {
$score = round($score);
$hasEmptyDecimals = true;
}
}
if (is_int($score) || is_string($score)) {
$score = (float) $score;
$check = fmod($score, 1);
if (0 === bccomp(0, $check)) {
$hasEmptyDecimals = true;
}
}
return $hasEmptyDecimals;
}
/**
* Display a score according to the current settings.
*
@ -290,6 +324,7 @@ class ScoreDisplay
* (only taken into account if custom score display is enabled and for course/platform admin)
* @param bool $disableColor
* @param bool $ignoreDecimals
* @param bool $removeEmptyDecimals Replaces 100.00 to 100
*
* @return string
*/
@ -298,10 +333,10 @@ class ScoreDisplay
$type = SCORE_DIV_PERCENT,
$what = SCORE_BOTH,
$disableColor = false,
$ignoreDecimals = false
$ignoreDecimals = false,
$removeEmptyDecimals = false
) {
$my_score = $score == 0 ? [] : $score;
switch ($type) {
case SCORE_BAR:
$percentage = $my_score[0] / $my_score[1] * 100;
@ -309,26 +344,28 @@ class ScoreDisplay
return Display::bar_progress($percentage);
break;
case SCORE_NUMERIC:
$percentage = $my_score[0] / $my_score[1] * 100;
return round($percentage);
break;
case SCORE_SIMPLE:
if (!isset($my_score[0])) {
$my_score[0] = 0;
}
return $this->format_score($my_score[0], $ignoreDecimals);
break;
}
if ($this->custom_enabled && isset($this->custom_display_conv)) {
$display = $this->display_default($my_score, $type, $ignoreDecimals);
$display = $this->displayDefault($my_score, $type, $ignoreDecimals, $removeEmptyDecimals);
} else {
// if no custom display set, use default display
$display = $this->display_default($my_score, $type, $ignoreDecimals);
$display = $this->displayDefault($my_score, $type, $ignoreDecimals, $removeEmptyDecimals);
}
if ($this->coloring_enabled && $disableColor == false) {
$my_score_denom = isset($score[1]) && !empty($score[1]) && $score[1] > 0 ? $score[1] : 1;
$denom = isset($score[1]) && !empty($score[1]) && $score[1] > 0 ? $score[1] : 1;
$scoreCleaned = isset($score[0]) ? $score[0] : 0;
if (($scoreCleaned / $my_score_denom) < ($this->color_split_value / 100)) {
if (($scoreCleaned / $denom) < ($this->color_split_value / 100)) {
$display = Display::tag(
'font',
$display,
@ -353,8 +390,8 @@ class ScoreDisplay
return null;
}
$my_score_denom = $score[1] == 0 ? 1 : $score[1];
$scaledscore = $score[0] / $my_score_denom;
$denom = $score[1] == 0 ? 1 : $score[1];
$scaledscore = $score[0] / $denom;
if ($this->upperlimit_included) {
foreach ($this->custom_display_conv as $displayitem) {
@ -398,21 +435,24 @@ class ScoreDisplay
}
/**
* @param $score
* @param int $type
* @param bool $ignoreDecimals
* @param array $score
* @param int $type
* @param bool $ignoreDecimals
* @param bool $removeEmptyDecimals
*
* @return string
*/
private function display_default($score, $type, $ignoreDecimals = false)
private function displayDefault($score, $type, $ignoreDecimals = false, $removeEmptyDecimals = false)
{
switch ($type) {
case SCORE_DIV: // X / Y
return $this->display_as_div($score, $ignoreDecimals);
return $this->display_as_div($score, $ignoreDecimals, $removeEmptyDecimals);
case SCORE_PERCENT: // XX %
return $this->display_as_percent($score);
case SCORE_DIV_PERCENT: // X / Y (XX %)
return $this->display_as_div($score).' ('.$this->display_as_percent($score).')';
//return $this->display_as_div($score).' ('.$this->display_as_percent($score).')';
// 2020-10 Changed to XX % (X / Y)
return $this->display_as_percent($score).' ('.$this->display_as_div($score).')';
case SCORE_AVERAGE: // XX %
return $this->display_as_percent($score);
case SCORE_DECIMAL: // 0.50 (X/Y)
@ -422,8 +462,13 @@ class ScoreDisplay
if (!empty($custom)) {
$custom = ' - '.$custom;
}
return $this->display_as_div($score).' ('.$this->display_as_percent($score).')'.$custom;
$div = $this->display_as_div($score, false, $removeEmptyDecimals);
/*return
$div.
' ('.$this->display_as_percent($score).')'.$custom;*/
return
$this->display_as_percent($score).
' ('.$div.')'.$custom;
case SCORE_DIV_SIMPLE_WITH_CUSTOM: // X - Good!
$custom = $this->display_custom($score);
@ -471,7 +516,7 @@ class ScoreDisplay
}
/**
* Returns "1" for array("100", "100");.
* Returns "1" for array("100", "100").
*
* @param array $score
*
@ -479,33 +524,34 @@ class ScoreDisplay
*/
private function display_as_decimal($score)
{
$score_denom = ($score[1] == 0) ? 1 : $score[1];
$score_denom = $score[1] == 0 ? 1 : $score[1];
return $this->format_score($score[0] / $score_denom);
}
/**
* Returns "100 %" for array("100", "100");.
* Returns "100 %" for array("100", "100").
*/
private function display_as_percent($score)
{
if (empty($score)) {
return null;
}
$score_denom = ($score[1] == 0) ? 1 : $score[1];
$scoreDenom = $score[1] == 0 ? 1 : $score[1];
return $this->format_score($score[0] / $score_denom * 100).' %';
return $this->format_score($score[0] / $scoreDenom * 100).' %';
}
/**
* Returns 10.00 / 10.00 for array("100", "100");.
* Returns 10.00 / 10.00 for array("100", "100").
*
* @param array $score
* @param bool $ignoreDecimals
* @param bool $removeEmptyDecimals
*
* @return string
*/
private function display_as_div($score, $ignoreDecimals = false)
private function display_as_div($score, $ignoreDecimals = false, $removeEmptyDecimals = false)
{
if ($score == 1) {
return '0 / 0';
@ -516,7 +562,13 @@ class ScoreDisplay
}
$score[0] = isset($score[0]) ? $this->format_score($score[0], $ignoreDecimals) : 0;
$score[1] = isset($score[1]) ? $this->format_score($score[1], $ignoreDecimals) : 0;
$score[1] = isset($score[1]) ? $this->format_score(
$score[1],
$ignoreDecimals,
'.',
',',
$removeEmptyDecimals
) : 0;
return $score[0].' / '.$score[1];
}
@ -607,9 +659,9 @@ class ScoreDisplay
}
return $converted2;
} else {
return null;
}
return null;
}
/**

@ -2926,11 +2926,11 @@ HOTSPOT;
$html = $percentage.$percentageSign;
}
} else {
/*if ($removeEmptyDecimals) {
if ($removeEmptyDecimals) {
if (ScoreDisplay::hasEmptyDecimals($weight)) {
$weight = round($weight);
}
}*/
}
$html = $score.' / '.$weight;
}

@ -1690,6 +1690,14 @@ $_configuration['auth_password_links'] = [
//CREATE TABLE c_lp_category_rel_usergroup (id INT AUTO_INCREMENT NOT NULL, lp_category_id INT NOT NULL, usergroup_id INT NOT NULL, c_id INT NOT NULL, session_id INT, created_at DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;
//$_configuration['allow_lp_subscription_to_usergroups'] = false;
// Gradebook student pdf export settings
/*$_configuration['gradebook_pdf_export_settings'] = [
'hide_score_weight' => true,
];*/
// Use exercise score in platform settings in gradebook total rows/columns.
//$_configuration['gradebook_use_exercise_score_settings_in_total'] = false;
// KEEP THIS AT THE END
// -------- Custom DB changes
// Add user activation by confirmation email

Loading…
Cancel
Save