From dcab942f4fa1f904eab300fa66def87908ca556c Mon Sep 17 00:00:00 2001
From: Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de>
Date: Thu, 15 Aug 2024 16:23:13 +0200
Subject: [PATCH] make vips grade view consistent with course gradebook, fixes
 #262

---
 controllers/solutions.php                 | 35 +++++++++++++++--------
 views/solutions/participants_overview.php | 29 ++++++++-----------
 views/solutions/student_grade.php         | 30 ++++++-------------
 3 files changed, 44 insertions(+), 50 deletions(-)

diff --git a/controllers/solutions.php b/controllers/solutions.php
index b37b540..4549ac1 100644
--- a/controllers/solutions.php
+++ b/controllers/solutions.php
@@ -1487,19 +1487,33 @@ class SolutionsController extends StudipController
                 foreach ($this->items as $category => $list) {
                     foreach ($list as $item) {
                         if ($display == 'points') {
-                            $row[] = sprintf('%.1f', $p['items'][$category][$item['id']]['points']);
-                        } else if (isset($p['items'][$category][$item['id']]['weighting'])) {
-                            $row[] = sprintf('%.1f%%', $p['items'][$category][$item['id']]['weighting']);
+                            if (isset($p['items'][$category][$item['id']]['points'])) {
+                                $row[] = sprintf('%.1f', $p['items'][$category][$item['id']]['points']);
+                            } else {
+                                $row[] = '';
+                            }
                         } else {
-                            $row[] = '';
+                            if (isset($p['items'][$category][$item['id']]['percent'])) {
+                                $row[] = sprintf('%.1f%%', $p['items'][$category][$item['id']]['percent']);
+                            } else {
+                                $row[] = '';
+                            }
                         }
                     }
                 }
 
                 if ($display == 'points') {
-                    $row[] = sprintf('%.1f', $p['overall']['points']);
+                    if (isset($p['overall']['points'])) {
+                        $row[] = sprintf('%.1f', $p['overall']['points']);
+                    } else {
+                        $row[] = '';
+                    }
                 } else {
-                    $row[] = sprintf('%.1f%%', $p['overall']['weighting']);
+                    if (isset($p['overall']['weighting'])) {
+                        $row[] = sprintf('%.1f%%', $p['overall']['weighting']);
+                    } else {
+                        $row[] = '';
+                    }
 
                     if ($this->has_grades) {
                         $row[] = $p['grade'];
@@ -1972,8 +1986,7 @@ function participants_overview_data($course_id, $param_user_id, $display = null,
                         // store reached points, percent and weighted percent for this item, for each group member
                         $participants[$member_id]['items'][$category][$item_id] = [
                             'points'    => $reached_points,
-                            'percent'   => $percent,
-                            'weighting' => $weighted_percent
+                            'percent'   => $percent
                         ];
 
                         if (!isset($participants[$member_id]['overall'])) {
@@ -1995,13 +2008,12 @@ function participants_overview_data($course_id, $param_user_id, $display = null,
                         $participants[$member_id]['items']['tests_seen'][$assignment_id] = true;
 
                         if (!isset($participants[$member_id]['items']['blocks'][$item_id])) {
-                            $participants[$member_id]['items']['blocks'][$item_id] = ['points' => 0, 'percent' => 0, 'weighting' => 0];
+                            $participants[$member_id]['items']['blocks'][$item_id] = ['points' => 0, 'percent' => 0];
                         }
 
                         // store reached points, percent and weighted percent for this item, for each group member
                         $participants[$member_id]['items']['blocks'][$item_id]['points']    += $reached_points;
                         $participants[$member_id]['items']['blocks'][$item_id]['percent']   += $percent;
-                        $participants[$member_id]['items']['blocks'][$item_id]['weighting'] += $weighted_percent;
 
                         if (!isset($participants[$member_id]['overall'])) {
                             $participants[$member_id]['overall'] = ['points' => 0, 'weighting' => 0];
@@ -2020,8 +2032,7 @@ function participants_overview_data($course_id, $param_user_id, $display = null,
                 // store reached points, percent and weighted percent for this item
                 $participants[$user_id]['items'][$category][$item_id] = [
                     'points'    => $reached_points,
-                    'percent'   => $percent,
-                    'weighting' => $weighted_percent
+                    'percent'   => $percent
                 ];
 
                 if (!isset($participants[$user_id]['overall'])) {
diff --git a/views/solutions/participants_overview.php b/views/solutions/participants_overview.php
index 8d6350d..062f13a 100644
--- a/views/solutions/participants_overview.php
+++ b/views/solutions/participants_overview.php
@@ -165,24 +165,19 @@
                 <? foreach ($items as $category => $list) : ?>
                     <? foreach ($list as $item) : ?>
                         <td style="text-align: right; white-space: nowrap;">
-                            <span
+                            <? if ($display == 'points') : ?>
+                                <? if (isset($p['items'][$category][$item['id']]['points'])) : ?>
+                                    <?= sprintf('%.1f', $p['items'][$category][$item['id']]['points']) ?>
+                                <? else : ?>
+                                    &ndash;
+                                <? endif ?>
+                            <? else : ?>
                                 <? if (isset($p['items'][$category][$item['id']]['percent'])) : ?>
-                                    title="<?= sprintf(_vips('absolut: %.1f %%'), $p['items'][$category][$item['id']]['percent']) ?>"
-                                <? endif ?>>
-                                <? if ($display == 'points') : ?>
-                                    <? if (isset($p['items'][$category][$item['id']]['points'])) : ?>
-                                        <?= sprintf('%.1f', $p['items'][$category][$item['id']]['points']) ?>
-                                    <? else : ?>
-                                        &ndash;
-                                    <? endif ?>
-                                <? elseif ($display == 'weighting') : ?>
-                                    <? if (isset($p['items'][$category][$item['id']]['weighting'])) : ?>
-                                        <?= sprintf('%.1f %%', $p['items'][$category][$item['id']]['weighting']) ?>
-                                    <? else : ?>
-                                        &ndash;
-                                    <? endif ?>
+                                    <?= sprintf('%.1f %%', $p['items'][$category][$item['id']]['percent']) ?>
+                                <? else : ?>
+                                    &ndash;
                                 <? endif ?>
-                            </span>
+                            <? endif ?>
                         </td>
                     <? endforeach ?>
                 <? endforeach ?>
@@ -194,7 +189,7 @@
                         <? else: ?>
                             &ndash;
                         <? endif ?>
-                    <? elseif ($display == 'weighting') : ?>
+                    <? else : ?>
                         <? if (isset($p['overall']['weighting'])): ?>
                             <?= sprintf('%.1f %%', $p['overall']['weighting']) ?>
                         <? else: ?>
diff --git a/views/solutions/student_grade.php b/views/solutions/student_grade.php
index 30e0361..ba88649 100644
--- a/views/solutions/student_grade.php
+++ b/views/solutions/student_grade.php
@@ -20,9 +20,6 @@
                 <th style="text-align: right;">
                     <?= _vips('Gewichtung') ?>
                 </th>
-                <th style="text-align: right;">
-                    <?= _vips('gewichtete Prozent') ?>
-                </th>
             <? endif ?>
         </tr>
     </thead>
@@ -34,18 +31,14 @@
             <? foreach (['tests', 'blocks', 'exams'] as $category) : ?>
                 <? foreach ($items[$category] as $item) : ?>
                     <? if ($item['item']->isVisible($user_id) && $item['weighting']) : ?>
-                        <? $reached_points   = $me['items'][$category][$item['id']]['points'] ?>
-                        <? $percent          = $me['items'][$category][$item['id']]['percent'] ?>
-                        <? $weighted_percent = $me['items'][$category][$item['id']]['weighting'] ?>
-
                         <tr>
                             <td>
                                 <?= htmlReady($item['name']) ?>
                             </td>
 
                             <td style="text-align: right;">
-                                <? if (isset($reached_points)) : ?>
-                                    <?= sprintf('%g', $reached_points) ?>
+                                <? if (isset($me['items'][$category][$item['id']]['points'])) : ?>
+                                    <?= sprintf('%g', $me['items'][$category][$item['id']]['points']) ?>
                                 <? else : ?>
                                     &ndash;
                                 <? endif ?>
@@ -60,8 +53,8 @@
                             </td>
 
                             <td style="text-align: right;">
-                                <? if (isset($percent)) : ?>
-                                    <?= sprintf('%.1f %%', $percent) ?>
+                                <? if (isset($me['items'][$category][$item['id']]['percent'])) : ?>
+                                    <?= sprintf('%.1f %%', $me['items'][$category][$item['id']]['percent']) ?>
                                 <? else : ?>
                                     &ndash;
                                 <? endif ?>
@@ -71,14 +64,6 @@
                                 <td style="text-align: right;">
                                     <?= sprintf('%.1f %%', $item['weighting']) ?>
                                 </td>
-
-                                <td style="text-align: right;">
-                                    <? if (isset($weighted_percent)) : ?>
-                                        <?= sprintf('%.1f %%', $weighted_percent) ?>
-                                    <? else : ?>
-                                        &ndash;
-                                    <? endif ?>
-                                </td>
                             <? endif ?>
                         </tr>
                     <? endif ?>
@@ -88,16 +73,19 @@
 
         <tfoot>
             <tr>
-                <td colspan="<?= $use_weighting ? 6 : 4 ?>" style="padding: 5px;">
+                <td colspan="4" style="padding: 5px;">
                     <?= _vips('Prozent, gesamt') ?>
                 </td>
                 <td style="padding: 5px; text-align: right;">
                     <?= sprintf('%.1f %%', $me['overall']['weighting']) ?>
                 </td>
+                <? if ($use_weighting) : ?>
+                    <td></td>
+                <? endif ?>
             </tr>
 
             <tr style="font-weight: bold;">
-                <td colspan="<?= $use_weighting ? 7 : 5 ?>" style="text-align: center;">
+                <td colspan="<?= $use_weighting ? 6 : 5 ?>" style="text-align: center;">
                     <?= _vips('Note:') ?>
                     <?= htmlReady($me['grade']) ?>
                     <? if ($me['grade_comment'] != '') : ?>
-- 
GitLab