From 39e27a71e76e8f9643eff744d157b17e8143f4f4 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Mon, 31 Mar 2025 14:18:54 +0000 Subject: [PATCH 1/8] prevent php8 warnings --- exercises/tb_exercise.php | 2 +- views/exercises/courseware_block.php | 2 +- views/exercises/lt_exercise/solve.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/tb_exercise.php b/exercises/tb_exercise.php index de245ff..443f7f3 100644 --- a/exercises/tb_exercise.php +++ b/exercises/tb_exercise.php @@ -156,7 +156,7 @@ class tb_exercise extends Exercise public function getSolutionFromRequest($request, $files = null) { $solution = parent::getSolutionFromRequest($request, $files); - $upload = $files['upload'] ?: ['name' => []]; + $upload = isset($files['upload']) ? $files['upload'] : ['name' => []]; $uploads = []; $solution_files = []; diff --git a/views/exercises/courseware_block.php b/views/exercises/courseware_block.php index 3153455..fe51868 100644 --- a/views/exercises/courseware_block.php +++ b/views/exercises/courseware_block.php @@ -59,7 +59,7 @@ <? if (!empty($exercise->options['comment'])): ?> <label> <?= _vips('Bemerkungen zur Lösung (optional)') ?> - <textarea name="student_comment"><?= htmlReady($solution->student_comment) ?></textarea> + <textarea name="student_comment"><?= htmlReady(isset($solution->student_comment) ? $solution->student_comment : '') ?></textarea> </label> <? endif ?> <? endif ?> diff --git a/views/exercises/lt_exercise/solve.php b/views/exercises/lt_exercise/solve.php index 9d82fcf..9959a71 100644 --- a/views/exercises/lt_exercise/solve.php +++ b/views/exercises/lt_exercise/solve.php @@ -1,4 +1,4 @@ <label> <?= _vips('Antwort') ?> - <input type="text" class="character_input" name="answer[0]" value="<?= htmlReady($response[0]) ?>"> + <input type="text" class="character_input" name="answer[0]" value="<?= htmlReady(isset($response[0]) ? $response[0] : '') ?>"> </label> -- GitLab From 824ad5b513e0f42e310036fc96898e0d5a1fe55d Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Tue, 1 Apr 2025 10:12:53 +0000 Subject: [PATCH 2/8] prevent another warning --- exercises/mc_exercise.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/mc_exercise.php b/exercises/mc_exercise.php index c7ff99a..0c94fa5 100644 --- a/exercises/mc_exercise.php +++ b/exercises/mc_exercise.php @@ -42,7 +42,7 @@ class mc_exercise extends Exercise if (trim($answer) != '') { $this->task['answers'][] = [ 'text' => trim($answer), - 'score' => (int) $request['correct'][$i] + 'score' => (int) ($request['correct'][$i] ?? 0) ]; } } -- GitLab From b702118394a1e0613df22bbc4ce9d3834f8291fc Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Tue, 1 Apr 2025 10:13:58 +0000 Subject: [PATCH 3/8] Apply 1 suggestion(s) to 1 file(s) --- exercises/mc_exercise.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/mc_exercise.php b/exercises/mc_exercise.php index 0c94fa5..d40c84d 100644 --- a/exercises/mc_exercise.php +++ b/exercises/mc_exercise.php @@ -42,7 +42,7 @@ class mc_exercise extends Exercise if (trim($answer) != '') { $this->task['answers'][] = [ 'text' => trim($answer), - 'score' => (int) ($request['correct'][$i] ?? 0) + 'score' => isset($request['correct'][$i]) ? (int) $request['correct'][$i] : 0 ]; } } -- GitLab From 4f6cedc244d180b130db0a298b093e1521ba103a Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Tue, 1 Apr 2025 11:41:04 +0000 Subject: [PATCH 4/8] prevent warning in cloze exercise --- exercises/cloze_exercise.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/cloze_exercise.php b/exercises/cloze_exercise.php index 213a381..27ca064 100644 --- a/exercises/cloze_exercise.php +++ b/exercises/cloze_exercise.php @@ -236,7 +236,7 @@ class cloze_exercise extends Exercise public function availableAnswers($solution) { $answers = []; - $response = $solution->response ?: []; + $response = !empty($solution->response) ? $solution->response : []; foreach ($this->task['answers'] as $answer) { foreach ($answer as $option) { -- GitLab From 457d20863be05c9f059c273a4f25883d181894ce Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Tue, 1 Apr 2025 11:42:58 +0000 Subject: [PATCH 5/8] prevent another warning in cloze solve view --- views/exercises/cloze_exercise/solve.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/exercises/cloze_exercise/solve.php b/views/exercises/cloze_exercise/solve.php index a2243d7..9a84f04 100644 --- a/views/exercises/cloze_exercise/solve.php +++ b/views/exercises/cloze_exercise/solve.php @@ -16,7 +16,7 @@ <option value=""> </option> <? endif ?> <? foreach ($exercise->task['answers'][$blank] as $option): ?> - <option value="<?= htmlReady($option['text']) ?>" <?= trim($option['text']) === $response[$blank] ? ' selected' : '' ?>> + <option value="<?= htmlReady($option['text']) ?>" <?= isset($response[$blank]) && trim($option['text']) === $response[$blank] ? ' selected' : '' ?>> <?= htmlReady($option['text']) ?> </option> <? endforeach ?> -- GitLab From 768defefd1dd72b4e14302a10ee8f6cda9097d47 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Tue, 1 Apr 2025 11:46:08 +0000 Subject: [PATCH 6/8] prevent warning in correction view for tb exercise --- views/exercises/tb_exercise/correct.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/exercises/tb_exercise/correct.php b/views/exercises/tb_exercise/correct.php index 644c264..8508a46 100644 --- a/views/exercises/tb_exercise/correct.php +++ b/views/exercises/tb_exercise/correct.php @@ -21,7 +21,7 @@ </ul> <div id="commented-<?= $exercise->id ?>"> - <? if ($edit_solution): ?> + <? if ($!empty(edit_solution)): ?> <? if ($exercise->getLayout() === 'markup'): ?> <? $answer = $response[0] ?> <? elseif ($exercise->getLayout() === 'code'): ?> -- GitLab From f27bcbd382fb1be282c056ea6f8a1d1fed65edb9 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Tue, 1 Apr 2025 12:04:43 +0000 Subject: [PATCH 7/8] prevent warnings in lt exercise --- exercises/lt_exercise.php | 62 ++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/exercises/lt_exercise.php b/exercises/lt_exercise.php index c658134..a60b69a 100644 --- a/exercises/lt_exercise.php +++ b/exercises/lt_exercise.php @@ -81,36 +81,38 @@ class lt_exercise extends Exercise if ($musterLoesung === $studentSolution) { $similarity_temp = 1; - } else if ($this->task['compare'] === 'levenshtein') { // Levenshtein-Distanz - $string1 = mb_substr($studentSolution, 0, 255); - $string2 = mb_substr($musterLoesung, 0, 255); - $divisor = max(mb_strlen($string1), mb_strlen($string2)); - - $levenshtein = vips_levenshtein($string1, $string2) / $divisor; - $similarity_temp = 1 - $levenshtein; - } else if ($this->task['compare'] === 'soundex') { // Soundex-Aussprache - $levenshtein = levenshtein(soundex($musterLoesung), soundex($studentSolution)); - - if ($levenshtein == 0) { - $similarity_temp = 0.8; - } else if ($levenshtein == 1) { - $similarity_temp = 0.6; - } else if ($levenshtein == 2) { - $similarity_temp = 0.4; - } else if ($levenshtein == 3) { - $similarity_temp = 0.2; - } else {// $levenshtein == 4 - $similarity_temp = 0; - } - } else if ($this->task['compare'] === 'numeric') { - $correct = normalizeFloat($answer['text'], $correct_unit); - $student = normalizeFloat($response[0], $student_unit); - - if ($correct_unit === $student_unit) { - if (abs($correct - $student) <= abs($correct * $this->task['epsilon'])) { - $similarity_temp = 1; - } else { - $safe = true; + } else if (isset($this->task['compare'])) { + if ($this->task['compare'] === 'levenshtein') { // Levenshtein-Distanz + $string1 = mb_substr($studentSolution, 0, 255); + $string2 = mb_substr($musterLoesung, 0, 255); + $divisor = max(mb_strlen($string1), mb_strlen($string2)); + + $levenshtein = vips_levenshtein($string1, $string2) / $divisor; + $similarity_temp = 1 - $levenshtein; + } else if ($this->task['compare'] === 'soundex') { // Soundex-Aussprache + $levenshtein = levenshtein(soundex($musterLoesung), soundex($studentSolution)); + + if ($levenshtein == 0) { + $similarity_temp = 0.8; + } else if ($levenshtein == 1) { + $similarity_temp = 0.6; + } else if ($levenshtein == 2) { + $similarity_temp = 0.4; + } else if ($levenshtein == 3) { + $similarity_temp = 0.2; + } else {// $levenshtein == 4 + $similarity_temp = 0; + } + } else if ($this->task['compare'] === 'numeric') { + $correct = normalizeFloat($answer['text'], $correct_unit); + $student = normalizeFloat($response[0], $student_unit); + + if ($correct_unit === $student_unit) { + if (abs($correct - $student) <= abs($correct * $this->task['epsilon'])) { + $similarity_temp = 1; + } else { + $safe = true; + } } } } -- GitLab From 8f5bc2990dd45af565de0fd284533380e05e5c08 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Thu, 3 Apr 2025 11:25:20 +0000 Subject: [PATCH 8/8] prevent more php warnings --- views/exercises/cloze_exercise/solve.php | 2 +- views/exercises/tb_exercise/correct.php | 4 ++-- views/exercises/tb_exercise/solve.php | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/views/exercises/cloze_exercise/solve.php b/views/exercises/cloze_exercise/solve.php index 9a84f04..6f7ef23 100644 --- a/views/exercises/cloze_exercise/solve.php +++ b/views/exercises/cloze_exercise/solve.php @@ -23,7 +23,7 @@ </select><!-- <? else: ?> --><input type="text" class="character_input cloze_input" name="answer[<?= $blank ?>]" - style="width: <?= $exercise->getInputWidth($blank) ?>em;" value="<?= htmlReady($response[$blank]) ?>"><!-- + style="width: <?= $exercise->getInputWidth($blank) ?>em;" value="<?= htmlReady(isset($response[$blank]) ? $response[$blank] : '') ?>"><!-- <? endif ?> <? endif ?> <? endforeach ?> diff --git a/views/exercises/tb_exercise/correct.php b/views/exercises/tb_exercise/correct.php index 8508a46..181c556 100644 --- a/views/exercises/tb_exercise/correct.php +++ b/views/exercises/tb_exercise/correct.php @@ -21,7 +21,7 @@ </ul> <div id="commented-<?= $exercise->id ?>"> - <? if ($!empty(edit_solution)): ?> + <? if (!empty($edit_solution)): ?> <? if ($exercise->getLayout() === 'markup'): ?> <? $answer = $response[0] ?> <? elseif ($exercise->getLayout() === 'code'): ?> @@ -66,7 +66,7 @@ <? endif ?> </div> - <? if ($edit_solution): ?> + <? if (!empty($edit_solution)): ?> <?= Studip\Button::create(_vips('Lösung bearbeiten'), 'edit_solution', ['class' => 'edit_solution']) ?> <? if ($exercise->getLayout() === 'code'): ?> diff --git a/views/exercises/tb_exercise/solve.php b/views/exercises/tb_exercise/solve.php index bdb807d..84c3b69 100644 --- a/views/exercises/tb_exercise/solve.php +++ b/views/exercises/tb_exercise/solve.php @@ -1,5 +1,5 @@ <? if ($exercise->getLayout() !== 'none'): ?> - <? if ($exercise->task['template'] != ''): ?> + <? if (!empty($exercise->task['template'])): ?> <div class="vips_tabs"> <ul> <li> @@ -20,7 +20,7 @@ <? /* student answer */ ?> <div id="solution-<?= $exercise->id ?>"> - <? $answer = isset($response) ? $response[0] : $exercise->task['template'] ?> + <? $answer = isset($response) ? $response[0] : (isset($exercise->task['template']) ? $exercise->task['template'] : '') ?> <? if ($exercise->getLayout() === 'markup'): ?> <textarea name="answer[0]" class="character_input size-l wysiwyg" data-editor="removePlugins=studip-quote,studip-upload,ImageUpload" rows="20"><?= wysiwygReady($answer) ?></textarea> <? elseif ($exercise->getLayout() === 'code'): ?> @@ -35,7 +35,7 @@ <? endif ?> </div> - <? if ($exercise->task['template'] == ''): ?> + <? if (empty($exercise->task['template'])): ?> </label> <? else: ?> <? /* default answer */ ?> -- GitLab