private function MultichoiceQuestion::_normalizeAlternative in Quiz 7.5
Same name and namespace in other branches
- 7.6 question_types/multichoice/multichoice.classes.inc \MultichoiceQuestion::_normalizeAlternative()
- 7.4 question_types/multichoice/multichoice.classes.inc \MultichoiceQuestion::_normalizeAlternative()
Helper function. Normalizes alternatives.
Parameters
array $alternatives:
Return value
array
2 calls to MultichoiceQuestion::_normalizeAlternative()
- MultichoiceQuestion::insertAlternative in question_types/
multichoice/ multichoice.classes.inc - Helper function. Saves new alternatives.
- MultichoiceQuestion::updateAlternative in question_types/
multichoice/ multichoice.classes.inc - Helper function. Updates existing alternatives.
File
- question_types/
multichoice/ multichoice.classes.inc, line 194 - Multichoice classes.
Class
- MultichoiceQuestion
- Extension of QuizQuestion.
Code
private function _normalizeAlternative($alternatives) {
$copy = $alternatives;
// Answer and answer format.
if (is_array($alternatives['answer'])) {
$copy['answer'] = array_key_exists('value', $alternatives['answer']) ? $alternatives['answer']['value'] : NULL;
$copy['answer_format'] = array_key_exists('format', $alternatives['answer']) ? $alternatives['answer']['format'] : NULL;
}
// Feedback if chosen and feedback if chosen format.
if (is_array($alternatives['feedback_if_chosen'])) {
$copy['feedback_if_chosen'] = array_key_exists('value', $alternatives['feedback_if_chosen']) ? $alternatives['feedback_if_chosen']['value'] : NULL;
$copy['feedback_if_chosen_format'] = array_key_exists('format', $alternatives['feedback_if_chosen']) ? $alternatives['feedback_if_chosen']['format'] : NULL;
}
// Feedback if not chosen and feedback if not chosen format.
if (is_array($alternatives['feedback_if_not_chosen'])) {
$copy['feedback_if_not_chosen'] = array_key_exists('value', $alternatives['feedback_if_not_chosen']) ? $alternatives['feedback_if_not_chosen']['value'] : NULL;
$copy['feedback_if_not_chosen_format'] = array_key_exists('format', $alternatives['feedback_if_not_chosen']) ? $alternatives['feedback_if_not_chosen']['format'] : NULL;
}
return $copy;
}