Skip to content
Permalink
Browse files

Add option "hide_gradebook_percentage_user_result" + fix rank column

- Hide percentage in best/average gradebook results

See BT#14972
  • Loading branch information...
jmontoyaa committed Oct 31, 2018
1 parent cbf3bb6 commit 40dcc1e7b49ce8ef263052be2abd3d73bb5db7b3
@@ -4,8 +4,6 @@
use ChamiloSession as Session;
/**
* Script.
*
* @package chamilo.gradebook
*/
require_once __DIR__.'/../inc/global.inc.php';
@@ -1602,7 +1602,6 @@ public static function generateTable(
$userInfo = api_get_user_info($userId);
$cat = $cats[0];
$allcat = $cats[0]->get_subcategories(
$userId,
api_get_course_id(),
@@ -1619,7 +1618,6 @@ public static function generateTable(
$loadStats = [2];
}
}
$gradebooktable = new GradebookTable(
$cat,
$allcat,
@@ -199,7 +199,7 @@ public function calc_score($stud_id = null, $type = null)
if ($exercise->exercise_was_added_in_lp == false) {
$sql = "SELECT * FROM $tblStats
WHERE
exe_exo_id = ".$exerciseId." AND
exe_exo_id = $exerciseId AND
orig_lp_id = 0 AND
orig_lp_item_id = 0 AND
status <> 'incomplete' AND
@@ -217,7 +217,7 @@ public function calc_score($stud_id = null, $type = null)
$sql = "SELECT *
FROM $tblStats
WHERE
exe_exo_id = ".$exerciseId." AND
exe_exo_id = $exerciseId AND
orig_lp_id = $lpId AND
status <> 'incomplete' AND
session_id = $sessionId AND
@@ -246,6 +246,7 @@ public function calc_score($stud_id = null, $type = null)
if (isset($stud_id) && empty($type)) {
// for 1 student
if ($data = Database::fetch_array($scores)) {
return [$data['exe_result'], $data['exe_weighting']];
} else {
return null;
@@ -79,6 +79,7 @@ public function __construct(
$this->cats = $cats;
$this->loadStats = $loadStats;
$this->datagen = new GradebookDataGenerator($cats, $evals, $links);
$this->datagen->hidePercentage = api_get_configuration_value('hide_gradebook_percentage_user_result');
if (!empty($userId)) {
$this->datagen->userId = $userId;
@@ -684,9 +685,9 @@ public function get_table_data($from = 1, $per_page = null, $column = null, $dir
);
$row = [
null,
'<h3>'.get_lang('Total').'</h3>',
];
null,
'<h3>'.get_lang('Total').'</h3>',
];
if (!$this->exportToPdf) {
$row[] = null;
@@ -699,8 +700,9 @@ public function get_table_data($from = 1, $per_page = null, $column = null, $dir
$totalRanking = [];
$invalidateRanking = true;
$average = 0;
$main_cat[0]->setStudentList($this->studentList);
foreach ($this->studentList as $student) {
$score = $main_cat[0]->calc_score($student['user_id']);
$score = $main_cat[0]->calc_score($student['user_id'], null, api_get_course_id());
if (!empty($score[0])) {
$invalidateRanking = false;
}
@@ -711,11 +713,11 @@ public function get_table_data($from = 1, $per_page = null, $column = null, $dir
$totalRanking = AbstractLink::getCurrentUserRanking($user_id, $totalRanking);
$totalRanking = $scoredisplay->display_score(
$totalRanking,
SCORE_DIV,
SCORE_BOTH,
true
);
$totalRanking,
SCORE_DIV,
SCORE_BOTH,
true
);
if ($invalidateRanking) {
$totalRanking = null;
@@ -728,18 +730,17 @@ public function get_table_data($from = 1, $per_page = null, $column = null, $dir
$totalBest[1] = $main_weight;
$totalBest = $scoredisplay->display_score(
$totalBest,
SCORE_DIV,
SCORE_BOTH,
true
);
$totalBest,
SCORE_DIV,
SCORE_BOTH,
true
);
$row[] = $totalBest;
}
if (in_array(3, $this->loadStats)) {
// Overwrite main weight
$totalAverage[0] = $average / count($this->studentList);
$totalAverage[1] = $main_weight;
$totalAverage = $scoredisplay->display_score(
$totalAverage,
SCORE_DIV,
@@ -749,7 +750,6 @@ public function get_table_data($from = 1, $per_page = null, $column = null, $dir
$row[] = $totalAverage;
}
$sortable_data[] = $row;
}
}
@@ -22,6 +22,7 @@ class GradebookDataGenerator
const GDG_SORT_DESC = 64;
const GDG_SORT_ID = 128;
public $userId;
public $hidePercentage = false;
private $items;
private $evals_links;
@@ -353,10 +354,15 @@ private function buildBestResultColumn(GradebookItem $item)
api_get_session_id()
);
$scoreMode = SCORE_DIV_PERCENT_WITH_CUSTOM;
if ($this->hidePercentage) {
$scoreMode = SCORE_DIV;
}
$scoreDisplay = ScoreDisplay::instance();
$display = $scoreDisplay->display_score(
$score,
SCORE_DIV_PERCENT_WITH_CUSTOM,
$scoreMode,
SCORE_BOTH,
true
);
@@ -380,15 +386,26 @@ private function buildAverageResultColumn(GradebookItem $item)
{
$score = $item->calc_score(null, 'average');
$scoreDisplay = ScoreDisplay::instance();
$scoreMode = SCORE_DIV_PERCENT_WITH_CUSTOM;
if ($this->hidePercentage) {
$scoreMode = SCORE_DIV;
}
$display = $scoreDisplay->display_score(
$score,
SCORE_DIV_PERCENT_WITH_CUSTOM,
$scoreMode,
SCORE_BOTH,
true
);
$type = $item->get_item_type();
if ($type === 'L' && get_class($item) === 'ExerciseLink') {
$display = ExerciseLib::show_score($score[0], $score[1], false);
$result = ExerciseLib::convertScoreToPlatformSetting($score[0], $score[1]);
$score[0] = $result['score'];
$score[1] = $result['weight'];
}
return [
@@ -2746,6 +2746,31 @@ public static function get_exam_results_data(
return $listInfo;
}
/**
* @param $score
* @param $weight
*
* @return array
*/
public static function convertScoreToPlatformSetting($score, $weight)
{
$result = ['score' => $score, 'weight' => $weight];
$maxNote = api_get_setting('exercise_max_score');
$minNote = api_get_setting('exercise_min_score');
if ($maxNote != '' && $minNote != '') {
if (!empty($weight) && intval($weight) != 0) {
$score = $minNote + ($maxNote - $minNote) * $score / $weight;
} else {
$score = $minNote;
}
$weight = $maxNote;
}
return ['score' => $score, 'weight' => $weight];
}
/**
* Converts the score with the exercise_max_note and exercise_min_score
* the platform settings + formats the results using the float_format function.
@@ -2777,18 +2802,10 @@ public static function show_score(
return '-';
}
$maxNote = api_get_setting('exercise_max_score');
$minNote = api_get_setting('exercise_min_score');
if ($use_platform_settings) {
if ($maxNote != '' && $minNote != '') {
if (!empty($weight) && intval($weight) != 0) {
$score = $minNote + ($maxNote - $minNote) * $score / $weight;
} else {
$score = $minNote;
}
$weight = $maxNote;
}
$result = self::convertScoreToPlatformSetting($score, $weight);
$score = $result['score'];
$weight = $result['weight'];
}
$percentage = (100 * $score) / ($weight != 0 ? $weight : 1);
// Formats values
@@ -1009,6 +1009,9 @@
// Students can only upload one publication
// $_configuration['allow_only_one_student_publication_per_user'] = false;
// Hide percentage in best/average gradebook results
//$_configuration['hide_gradebook_percentage_user_result'] = true;
// ------ Custom DB changes (keep this at the end)
// Add user activation by confirmation email
// This option prevents the new user to login in the platform if your account is not confirmed via email

0 comments on commit 40dcc1e

Please sign in to comment.
You can’t perform that action at this time.