From f574edc7332c9af2eac30c248218780ba9dc44e0 Mon Sep 17 00:00:00 2001 From: Christian Beeznest Date: Tue, 18 Nov 2025 21:00:21 -0500 Subject: [PATCH] Exercise: Fix question type labels in admin question pool --- public/main/admin/questions.php | 61 +++++++++++++++++-------- public/main/exercise/question.class.php | 13 ++++-- public/main/exercise/question_pool.php | 6 ++- 3 files changed, 54 insertions(+), 26 deletions(-) diff --git a/public/main/admin/questions.php b/public/main/admin/questions.php index db69552a91d..db3dfe18131 100644 --- a/public/main/admin/questions.php +++ b/public/main/admin/questions.php @@ -63,11 +63,32 @@ // Answer type $answerType = isset($_REQUEST['answer_type']) ? (int) $_REQUEST['answer_type'] : null; $questionList = Question::getQuestionTypeList(); -$questionTypesList = []; -$questionTypesList['-1'] = get_lang('All'); +$questionTypesList = ['-1' => get_lang('All')]; foreach ($questionList as $key => $item) { - $questionTypesList[$key] = get_lang($item[1]); + // Try to use the Question instance naming logic + $instance = Question::getInstance($key); + if ($instance instanceof Question) { + $label = $instance->get_question_type_name(); + } else { + // Fallback: best-effort human-readable label + if (is_array($item)) { + $raw = $item[2] ?? $item[1] ?? reset($item); + } else { + $raw = (string) $item; + } + + // Try to translate; if not translated, keep a nicer label + $translated = get_lang($raw); + if ($translated !== $raw) { + $label = $translated; + } else { + // Turn "UniqueAnswer" into "Unique Answer" + $label = preg_replace('/(?read($exerciseId); $exerciseData .= $exercise->title.' '; $exerciseData .= Display::url( - Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit')), - $urlExercise.api_get_cidreq_params($courseInfo['id'], $exercise->sessionId).'&'.http_build_query( - [ - 'exerciseId' => $exerciseId, - 'type' => $question->getType(), - 'editQuestion' => $question->getIid(), - ] - ), - ['target' => '_blank'] - ).'
'; + Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit')), + $urlExercise.api_get_cidreq_params($courseInfo['id'], $exercise->sessionId).'&'.http_build_query( + [ + 'exerciseId' => $exerciseId, + 'type' => $question->getType(), + 'editQuestion' => $question->getIid(), + ] + ), + ['target' => '_blank'] + ).'
'; } $question->questionData .= '
'.$exerciseData; } else { @@ -308,13 +329,13 @@ ); } $question->questionData .= '
'.Display::url( - get_lang('Delete'), - $deleteUrl, - [ - 'class' => 'btn btn--danger', - 'onclick' => 'javascript: if(!confirm(\''.$warningText.'\')) return false', - ] - ).'
'; + get_lang('Delete'), + $deleteUrl, + [ + 'class' => 'btn btn--danger', + 'onclick' => 'javascript: if(!confirm(\''.$warningText.'\')) return false', + ] + ).''; ob_end_clean(); } } diff --git a/public/main/exercise/question.class.php b/public/main/exercise/question.class.php index 8acd7315755..299c2281529 100644 --- a/public/main/exercise/question.class.php +++ b/public/main/exercise/question.class.php @@ -1143,16 +1143,21 @@ public function duplicate($courseInfo = []) */ public function get_question_type_name(): string { - $label = trim((string) $this->explanationLangVar); - if ($label !== '') { - return get_lang($label); + $labelKey = trim((string) $this->explanationLangVar); + if ($labelKey !== '') { + $translated = get_lang($labelKey); + if ($translated !== $labelKey) { + return $translated; + } } $def = self::$questionTypes[$this->type] ?? null; $className = is_array($def) ? ($def[1] ?? '') : ''; if ($className !== '') { $human = preg_replace('/(? $_) { if (isset($question_list[$key])) { $item = $question_list[$key]; - $new_question_list[$key] = get_lang($item[1]); + $labelKey = $item[2] ?? $item[1]; + $new_question_list[$key] = get_lang($labelKey); } } } else { @@ -471,7 +472,8 @@ function confirm_your_choice() { if (HOT_SPOT_DELINEATION == $key) { continue; } - $new_question_list[$key] = get_lang($item[1]); + $labelKey = $item[2] ?? $item[1]; + $new_question_list[$key] = get_lang($labelKey); } } }