type = DRAGGABLE; $this->isContent = $this->getIsContent(); } /** * Function which redefines Question::createAnswersForm * @param FormValidator instance */ public function createAnswersForm($form) { $defaults = array(); $nb_matches = $nb_options = 2; if ($form->isSubmitted()) { $nb_matches = $form->getSubmitValue('nb_matches'); $nb_options = $form->getSubmitValue('nb_options'); if (isset($_POST['lessMatches'])) { $nb_matches--; } if (isset($_POST['moreMatches'])) { $nb_matches++; } if (isset($_POST['lessOptions'])) { $nb_options--; } if (isset($_POST['moreOptions'])) { $nb_options++; } } else { if (!empty($this->id)) { $answer = new Answer($this->id, api_get_course_int_id()); $answer->read(); if (count($answer->nbrAnswers) > 0) { $nb_matches = $nb_options = 0; //for ($i = 1; $i <= $answer->nbrAnswers; $i++) { foreach ($answer->answer as $answerId => $answer_item) { //$answer_id = $answer->getRealAnswerIdFromList($answerId); if ($answer->isCorrect($answerId)) { $nb_matches++; $defaults['answer['.$nb_matches.']'] = $answer->selectAnswer($answerId); $defaults['weighting['.$nb_matches.']'] = Text::float_format($answer->selectWeighting($answerId), 1); $defaults['matches['.$nb_matches.']'] = $answer->correct[$answerId];//$nb_matches; } else { $nb_options++; $defaults['option['.$nb_options.']'] = $nb_options; } } } } else { $defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1'); $defaults['answer[2]'] = get_lang('DefaultMakeCorrespond2'); $defaults['matches[2]'] = '2'; $defaults['option[1]'] = get_lang('DefaultMatchingOptA'); $defaults['option[2]'] = get_lang('DefaultMatchingOptB'); } } $a_matches = array(); for ($i = 1; $i <= $nb_matches; ++$i) { $a_matches[$i] = $i; // fill the array with A, B, C..... } $form->addElement('hidden', 'nb_matches', $nb_matches); $form->addElement('hidden', 'nb_options', $nb_options); // DISPLAY MATCHES $html = '
'.get_lang('Answer').' | '.get_lang('MatchesTo').' | '.get_lang('Weighting').' |
---|---|---|
'); $group = array(); $group[] = $form->createElement('text', 'answer['.$i.']', null, ' size="60" style="margin-left: 0em;"'); $group[] = $form->createElement('select', 'matches['.$i.']', null, $a_matches); $group[] = $form->createElement( 'text', 'weighting['.$i.']', null, array('class' => 'span1', 'value' => 10, ) ); $form->addGroup($group, null, null, ' | '); $form->addElement('html', ' |
'.get_lang('ElementList').' | '.get_lang('Status').' |
---|