From c27974061c2fa953f7757d6c3d23cf4c2965c1a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Borja=20S=C3=A1nchez?= <114572427+BorjaSanchezBeezNest@users.noreply.github.com> Date: Mon, 28 Nov 2022 09:19:37 +0100 Subject: [PATCH] Gradebook - Hide links for tasks in gradebook when the user is a student - refs GH#4427 Author: @BorjaSanchezBeezNest --- main/exercise/TestCategory.php | 16 ++++++++++------ main/exercise/exercise.class.php | 13 +++++++++---- .../gradebook/lib/fe/gradebooktable.class.php | 19 +++++++++++++++---- main/install/configuration.dist.php | 3 +++ 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/main/exercise/TestCategory.php b/main/exercise/TestCategory.php index 2f3f95958d..eda0c9b085 100644 --- a/main/exercise/TestCategory.php +++ b/main/exercise/TestCategory.php @@ -804,15 +804,15 @@ class TestCategory 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 ) ); @@ -820,14 +820,18 @@ class TestCategory $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++; } diff --git a/main/exercise/exercise.class.php b/main/exercise/exercise.class.php index 49e8ccc5d1..13ee4002c2 100755 --- a/main/exercise/exercise.class.php +++ b/main/exercise/exercise.class.php @@ -11115,8 +11115,12 @@ class Exercise $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; } @@ -11175,11 +11179,12 @@ class Exercise $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; } } } diff --git a/main/gradebook/lib/fe/gradebooktable.class.php b/main/gradebook/lib/fe/gradebooktable.class.php index aa9806cd7f..8dbacb4150 100755 --- a/main/gradebook/lib/fe/gradebooktable.class.php +++ b/main/gradebook/lib/fe/gradebooktable.class.php @@ -300,6 +300,7 @@ class GradebookTable extends SortableTable 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 @@ -427,7 +428,17 @@ class GradebookTable extends SortableTable ''.Security::remove_XSS($item->get_name()).''.$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; } @@ -482,8 +493,8 @@ class GradebookTable extends SortableTable $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)) { @@ -538,7 +549,7 @@ class GradebookTable extends SortableTable $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 diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php index 52c0912a81..48085e405c 100755 --- a/main/install/configuration.dist.php +++ b/main/install/configuration.dist.php @@ -2310,6 +2310,9 @@ INSERT INTO `extra_field` (`extra_field_type`, `field_type`, `variable`, `displa // 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