public function ChoiceQuestion::validate in Quiz 6.6
Implementation of validate
(non-PHPdoc)
Overrides QuizQuestion::validate
See also
sites/all/modules/quiz-HEAD/question_types/quiz_question/QuizQuestion#validate()
File
- question_types/
choice/ choice.classes.inc, line 161 - The main classes for the choice question type.
Class
- ChoiceQuestion
- Implementation of QuizQuestion.
Code
public function validate($node, &$form) {
if ($node->choice_multi == 0) {
$found_one_correct = FALSE;
for ($i = 0; is_array($this->node->alternatives[$i]); $i++) {
$short = $this->node->alternatives[$i];
if (strlen(strip_tags($short['answer'])) < 1) {
continue;
}
if ($short['correct'] == 1) {
if ($found_one_correct) {
form_set_error("choice_multi", t('You have several alternatives marked as correct. If this is done intentionally you must must allow multiple alternatives to be correct.'));
}
else {
$found_one_correct = TRUE;
}
}
}
if (!$found_one_correct) {
form_set_error('choice_multi', t('You have not marked any alternatives as correct. If there are no correct alternatives you should allow multiple answers.'));
}
}
else {
for ($i = 0; is_array($this->node->alternatives[$i]); $i++) {
$short = $this->node->alternatives[$i];
if (strlen(strip_tags($short['answer'])) < 1) {
continue;
}
if ($short['score_if_chosen'] < $short['score_if_not_chosen'] && $short['correct']) {
form_set_error("alternatives][{$i}][score_if_not_chosen", t('The alternative is marked as correct, but gives more points if you don\'t select it.'));
}
elseif ($short['score_if_chosen'] > $short['score_if_not_chosen'] && !$short['correct']) {
form_set_error("alternatives][{$i}][score_if_chosen", t('The alternative is not marked as correct, but gives more points if you select it.'));
}
}
}
}