Skip to content

Commit

Permalink
Gradebook - Hide links for tasks in gradebook when the user is a stud…
Browse files Browse the repository at this point in the history
…ent - refs GH#4427

Author: @BorjaSanchezBeezNest
  • Loading branch information
BorjaSanchezBeezNest committed Nov 28, 2022
1 parent 6ba2629 commit c279740
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
16 changes: 10 additions & 6 deletions main/exercise/TestCategory.php
Expand Up @@ -804,30 +804,34 @@ public static function get_stats_table_by_attempt($exercise, $category_list = []
continue;
}
$labels[] = $title;
$category_item = $category_list[$category_id];
$categoryItem = $category_list[$category_id];

$table->setCellContents($row, 0, $title);
$table->setCellContents(
$row,
1,
ExerciseLib::show_score(
$category_item['score'],
$category_item['total'],
$categoryItem['score'],
$categoryItem['total'],
false
)
);
$table->setCellContents(
$row,
2,
ExerciseLib::show_score(
$category_item['score'],
$category_item['total'],
$categoryItem['score'],
$categoryItem['total'],
true,
false,
true
)
);
$tempResult[$category_id] = round($category_item['score'] / $category_item['total'] * 10);
if ($categoryItem['total'] > 0) {
$tempResult[$category_id] = round($categoryItem['score'] / $categoryItem['total'] * 10);
} else {
$tempResult[$category_id] = 0;
}
$row++;
}

Expand Down
13 changes: 9 additions & 4 deletions main/exercise/exercise.class.php
Expand Up @@ -11115,8 +11115,12 @@ public function getRadarsFromUsers($userList, $exercises, $dataSetLabels, $cours
$tempResult = [];
foreach ($labelsWithId as $category_id => $title) {
if (isset($categoryList[$category_id])) {
$category_item = $categoryList[$category_id];
$tempResult[] = round($category_item['score'] / $category_item['total'] * 10);
$categoryItem = $categoryList[$category_id];
if ($categoryItem['total'] > 0) {
$tempResult[] = round($categoryItem['score'] / $categoryItem['total'] * 10);
} else {
$tempResult[] = 0;
}
} else {
$tempResult[] = 0;
}
Expand Down Expand Up @@ -11175,11 +11179,12 @@ public function getAverageRadarsFromUsers($userList, $exercises, $dataSetLabels,
$categoryList = $stats['category_list'];
foreach ($labelsWithId as $category_id => $title) {
if (isset($categoryList[$category_id])) {
$category_item = $categoryList[$category_id];
$categoryItem = $categoryList[$category_id];
if (!isset($tempResult[$exerciseId][$category_id])) {
$tempResult[$exerciseId][$category_id] = 0;
}
$tempResult[$exerciseId][$category_id] += $category_item['score'] / $category_item['total'] * 10;
$tempResult[$exerciseId][$category_id] +=
$categoryItem['score'] / $categoryItem['total'] * 10;
}
}
}
Expand Down
19 changes: 15 additions & 4 deletions main/gradebook/lib/fe/gradebooktable.class.php
Expand Up @@ -300,6 +300,7 @@ public function get_table_data($from = 1, $per_page = null, $column = null, $dir
global $certificate_min_score;

$isAllowedToEdit = api_is_allowed_to_edit();
$hideLinkForStudent = api_get_configuration_value('gradebook_hide_link_to_item_for_student') ?? false;
// determine sorting type
$col_adjust = $isAllowedToEdit ? 1 : 0;
// By id
Expand Down Expand Up @@ -427,7 +428,17 @@ public function get_table_data($from = 1, $per_page = null, $column = null, $dir
'<strong>'.Security::remove_XSS($item->get_name()).'</strong>'.$invisibility_span_close;
$main_categories[$item->get_id()]['name'] = $item->get_name();
} else {
$name = Security::remove_XSS($this->build_name_link($item, $type));

// If the item type is 'Evaluation', or the user is not a student,
// or 'gradebook_hide_link_to_item_for_student' it's true, make links
if ($item->get_item_type() === 'E' || $isAllowedToEdit || !$hideLinkForStudent) {
$name = Security::remove_XSS($this->build_name_link($item, $type));
} else {
$name = Security::remove_XSS(
$item->get_name().' '.Display::label($item->get_type_name(), 'info')
);
}

$row[] = $invisibility_span_open.$name.$invisibility_span_close;
$main_categories[$item->get_id()]['name'] = $name;
}
Expand Down Expand Up @@ -482,8 +493,8 @@ public function get_table_data($from = 1, $per_page = null, $column = null, $dir
$ranking = isset($data['ranking']) ? $data['ranking'] : null;

$totalResult = [
$data['result_score'][0],
$data['result_score'][1],
$data['result_score'][0] ?? null,
$data['result_score'][1] ?? null,
];

if (empty($model)) {
Expand Down Expand Up @@ -538,7 +549,7 @@ public function get_table_data($from = 1, $per_page = null, $column = null, $dir

$this->dataForGraph['my_result'][] = floatval($totalResultAverageValue);
$this->dataForGraph['average'][] = floatval($totalAverageValue);
$this->dataForGraph['my_result_no_float'][] = $data['result_score'][0];
$this->dataForGraph['my_result_no_float'][] = $data['result_score'][0] ?? null;

if (empty($model)) {
// Ranking
Expand Down
3 changes: 3 additions & 0 deletions main/install/configuration.dist.php
Expand Up @@ -2310,6 +2310,9 @@
// Allow DRH user to access all students from reporting.
// $_configuration['drh_allow_access_to_all_students'] = false;

// Disable links in gradebook view for students
// $_configuration['gradebook_hide_link_to_item_for_student'] = false;

// KEEP THIS AT THE END
// -------- Custom DB changes
// Add user activation by confirmation email
Expand Down

0 comments on commit c279740

Please sign in to comment.