Skip to content

Commit d1b6fe6

Browse files
Merge pull request #7078 from christianbeeznest/fixes-updates185
Exercise: Fix question type labels in admin question pool
2 parents 5be6045 + f574edc commit d1b6fe6

File tree

3 files changed

+54
-26
lines changed

3 files changed

+54
-26
lines changed

public/main/admin/questions.php

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,32 @@
6363
// Answer type
6464
$answerType = isset($_REQUEST['answer_type']) ? (int) $_REQUEST['answer_type'] : null;
6565
$questionList = Question::getQuestionTypeList();
66-
$questionTypesList = [];
67-
$questionTypesList['-1'] = get_lang('All');
66+
$questionTypesList = ['-1' => get_lang('All')];
6867

6968
foreach ($questionList as $key => $item) {
70-
$questionTypesList[$key] = get_lang($item[1]);
69+
// Try to use the Question instance naming logic
70+
$instance = Question::getInstance($key);
71+
if ($instance instanceof Question) {
72+
$label = $instance->get_question_type_name();
73+
} else {
74+
// Fallback: best-effort human-readable label
75+
if (is_array($item)) {
76+
$raw = $item[2] ?? $item[1] ?? reset($item);
77+
} else {
78+
$raw = (string) $item;
79+
}
80+
81+
// Try to translate; if not translated, keep a nicer label
82+
$translated = get_lang($raw);
83+
if ($translated !== $raw) {
84+
$label = $translated;
85+
} else {
86+
// Turn "UniqueAnswer" into "Unique Answer"
87+
$label = preg_replace('/(?<!^)(?=[A-Z])/', ' ', $raw) ?: $raw;
88+
}
89+
}
90+
91+
$questionTypesList[$key] = $label;
7192
}
7293

7394
$form = new FormValidator('admin_questions', 'get');
@@ -262,16 +283,16 @@
262283
$exercise->read($exerciseId);
263284
$exerciseData .= $exercise->title.'&nbsp;';
264285
$exerciseData .= Display::url(
265-
Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit')),
266-
$urlExercise.api_get_cidreq_params($courseInfo['id'], $exercise->sessionId).'&'.http_build_query(
267-
[
268-
'exerciseId' => $exerciseId,
269-
'type' => $question->getType(),
270-
'editQuestion' => $question->getIid(),
271-
]
272-
),
273-
['target' => '_blank']
274-
).'<br />';
286+
Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit')),
287+
$urlExercise.api_get_cidreq_params($courseInfo['id'], $exercise->sessionId).'&'.http_build_query(
288+
[
289+
'exerciseId' => $exerciseId,
290+
'type' => $question->getType(),
291+
'editQuestion' => $question->getIid(),
292+
]
293+
),
294+
['target' => '_blank']
295+
).'<br />';
275296
}
276297
$question->questionData .= '<br />'.$exerciseData;
277298
} else {
@@ -308,13 +329,13 @@
308329
);
309330
}
310331
$question->questionData .= '<div class="float-right">'.Display::url(
311-
get_lang('Delete'),
312-
$deleteUrl,
313-
[
314-
'class' => 'btn btn--danger',
315-
'onclick' => 'javascript: if(!confirm(\''.$warningText.'\')) return false',
316-
]
317-
).'</div>';
332+
get_lang('Delete'),
333+
$deleteUrl,
334+
[
335+
'class' => 'btn btn--danger',
336+
'onclick' => 'javascript: if(!confirm(\''.$warningText.'\')) return false',
337+
]
338+
).'</div>';
318339
ob_end_clean();
319340
}
320341
}

public/main/exercise/question.class.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,16 +1143,21 @@ public function duplicate($courseInfo = [])
11431143
*/
11441144
public function get_question_type_name(): string
11451145
{
1146-
$label = trim((string) $this->explanationLangVar);
1147-
if ($label !== '') {
1148-
return get_lang($label);
1146+
$labelKey = trim((string) $this->explanationLangVar);
1147+
if ($labelKey !== '') {
1148+
$translated = get_lang($labelKey);
1149+
if ($translated !== $labelKey) {
1150+
return $translated;
1151+
}
11491152
}
11501153

11511154
$def = self::$questionTypes[$this->type] ?? null;
11521155
$className = is_array($def) ? ($def[1] ?? '') : '';
11531156
if ($className !== '') {
11541157
$human = preg_replace('/(?<!^)(?=[A-Z])/', ' ', $className) ?: $className;
1155-
return get_lang(trim($human));
1158+
$translated = get_lang($human);
1159+
1160+
return $translated !== $human ? $translated : $human;
11561161
}
11571162

11581163
return '';

public/main/exercise/question_pool.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,8 @@ function confirm_your_choice() {
461461
foreach ($allowedTypes as $key => $_) {
462462
if (isset($question_list[$key])) {
463463
$item = $question_list[$key];
464-
$new_question_list[$key] = get_lang($item[1]);
464+
$labelKey = $item[2] ?? $item[1];
465+
$new_question_list[$key] = get_lang($labelKey);
465466
}
466467
}
467468
} else {
@@ -471,7 +472,8 @@ function confirm_your_choice() {
471472
if (HOT_SPOT_DELINEATION == $key) {
472473
continue;
473474
}
474-
$new_question_list[$key] = get_lang($item[1]);
475+
$labelKey = $item[2] ?? $item[1];
476+
$new_question_list[$key] = get_lang($labelKey);
475477
}
476478
}
477479
}

0 commit comments

Comments
 (0)