Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 41 additions & 20 deletions public/main/admin/questions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('/(?<!^)(?=[A-Z])/', ' ', $raw) ?: $raw;
}
}

$questionTypesList[$key] = $label;
}

$form = new FormValidator('admin_questions', 'get');
Expand Down Expand Up @@ -262,16 +283,16 @@
$exercise->read($exerciseId);
$exerciseData .= $exercise->title.'&nbsp;';
$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']
).'<br />';
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']
).'<br />';
}
$question->questionData .= '<br />'.$exerciseData;
} else {
Expand Down Expand Up @@ -308,13 +329,13 @@
);
}
$question->questionData .= '<div class="float-right">'.Display::url(
get_lang('Delete'),
$deleteUrl,
[
'class' => 'btn btn--danger',
'onclick' => 'javascript: if(!confirm(\''.$warningText.'\')) return false',
]
).'</div>';
get_lang('Delete'),
$deleteUrl,
[
'class' => 'btn btn--danger',
'onclick' => 'javascript: if(!confirm(\''.$warningText.'\')) return false',
]
).'</div>';
ob_end_clean();
}
}
Expand Down
13 changes: 9 additions & 4 deletions public/main/exercise/question.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('/(?<!^)(?=[A-Z])/', ' ', $className) ?: $className;
return get_lang(trim($human));
$translated = get_lang($human);

return $translated !== $human ? $translated : $human;
}

return '';
Expand Down
6 changes: 4 additions & 2 deletions public/main/exercise/question_pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,8 @@ function confirm_your_choice() {
foreach ($allowedTypes as $key => $_) {
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 {
Expand All @@ -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);
}
}
}
Expand Down
Loading