Index: lang/en_utf8/form.php =================================================================== RCS file: /cvsroot/moodle/moodle/lang/en_utf8/form.php,v retrieving revision 1.17.4.1 diff -u -r1.17.4.1 form.php --- lang/en_utf8/form.php 6 Dec 2007 09:02:02 -0000 1.17.4.1 +++ lang/en_utf8/form.php 8 Nov 2008 23:48:22 -0000 @@ -28,6 +28,10 @@ $string['hour']='Hour'; $string['minute']='Minute'; +$string['apply'] = 'Apply'; +$string['edoptions'] = 'Editing options'; +$string['numofblanks'] = 'Number of blanks'; + $string['advancedelement']='Advanced element'; $string['hideadvanced']='Hide Advanced'; $string['showadvanced']='Show Advanced'; Index: lang/en_utf8/qtype_match.php =================================================================== RCS file: /cvsroot/moodle/moodle/lang/en_utf8/qtype_match.php,v retrieving revision 1.1.6.1 diff -u -r1.1.6.1 qtype_match.php --- lang/en_utf8/qtype_match.php 27 Oct 2008 02:33:28 -0000 1.1.6.1 +++ lang/en_utf8/qtype_match.php 8 Nov 2008 23:54:04 -0000 @@ -4,4 +4,5 @@ $string['nomatchinganswerforq'] = 'You must specify an answer for this question.'; $string['notenoughquestions'] = 'You must supply at least $a question and answer pairs.'; $string['notenoughqsandas'] = 'You must supply at least $a->q questions and $a->a answers.'; +$string['numberofblanks'] = 'Number of blanks for matches'; ?> \ No newline at end of file Index: lib/formslib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/formslib.php,v retrieving revision 1.129.2.18 diff -u -r1.129.2.18 formslib.php --- lib/formslib.php 22 Oct 2008 09:09:31 -0000 1.129.2.18 +++ lib/formslib.php 8 Nov 2008 23:52:24 -0000 @@ -529,28 +529,42 @@ * 'helpbutton' - helpbutton params array is value * 'disabledif' - last three moodleform::disabledIf() * params are value as an array - * @param string $repeathiddenname name for hidden element storing no of repeats in this form - * @param string $addfieldsname name for button to add more fields - * @param int $addfieldsno how many fields to add at a time - * @param string $addstring name of button, {no} is replaced by no of blanks that will be added. - * @param boolean $addbuttoninside if true, don't call closeHeaderBefore($addfieldsname). Default false. + * @param string $repeathiddenname name for hidden element storing OLD no of repeats in this form !!new meaning + * @param string $repeatname name for element to input no of repeats !!NEW + * @param string $groupname name for the group !!NEW + * @param string $headername name for the header!!NEW + * @param string $addfieldsname name for button to apply settings - !! new meaning + * @param int $addfieldsno how many fields to add at a time !!DELETED + * @param string $repeatstring string for label of repeats !!NEW + * @param string $headerstring string for the header of !!NEW + * @param string $addstring text of button - !!new meaning * @return int no of repeats of element in this page */ - function repeat_elements($elementobjs, $repeats, $options, $repeathiddenname, - $addfieldsname, $addfieldsno=5, $addstring=null, $addbuttoninside=false){ + function repeat_elements($elementobjs, $repeats, $options, $repeathiddenname, $repeatname, $groupname, + $headername, $addfieldsname, $repeatstring=null, $headerstring=null, $addstring=null){ if ($addstring===null){ - $addstring = get_string('addfields', 'form', $addfieldsno); - } else { - $addstring = str_ireplace('{no}', $addfieldsno, $addstring); + $addstring = get_string('apply', 'form'); + } + if($headerstring===null){ + $headerstring=get_string('edoptions', 'form'); } - $repeats = optional_param($repeathiddenname, $repeats, PARAM_INT); - $addfields = optional_param($addfieldsname, '', PARAM_TEXT); - if (!empty($addfields)){ - $repeats += $addfieldsno; + if($repeatstring===null){ + $repeatstring=get_string('numofblanks', 'form'); } + $oldrepeats = optional_param($repeathiddenname, 0, PARAM_INT); + $repeats = optional_param($repeatname, $repeats, PARAM_INT); + $mform =& $this->_form; - $mform->registerNoSubmitButton($addfieldsname); + $mform->addElement('header',$headername,$headerstring); + $mform->closeHeaderBefore($headername); + $mform->addElement('text',$repeatname,$repeatstring,array('size'=>3)); + $mform->addElement('submit',$addfieldsname,$addstring); $mform->addElement('hidden', $repeathiddenname, $repeats); + $mform->setDefault($repeatname,$repeats); + $mform->addRule($repeatname,null,'required',null,'client',true); + $mform->addRule($repeatname,null,'nonzero',null,'client',true); + $mform->addRule(array($repeatname, $repeathiddenname),'You can\'t delete blanks','compare','>=','client',true);//TODO get_string - well, the user doesn't really will see the message, but I leave it there just in case Jamie would normally fix MDL-17111 somewhere + $mform->registerNoSubmitButton($addfieldsname); //value not to be overridden by submitted value $mform->setConstants(array($repeathiddenname=>$repeats)); for ($i=0; $i<$repeats; $i++) { @@ -607,11 +621,6 @@ } } } - $mform->addElement('submit', $addfieldsname, $addstring); - - if (!$addbuttoninside) { - $mform->closeHeaderBefore($addfieldsname); - } return $repeats; } @@ -1335,11 +1344,22 @@ //unset($element); //$element =& $this->getElement($elementName); //end of fix - $valFunc = 'validate_' . $this->_formName . '_' . $elementName . '(this)'; - $onBlur = $element->getAttribute('onBlur'); - $onChange = $element->getAttribute('onChange'); - $element->updateAttributes(array('onBlur' => $onBlur . $valFunc, + //Rough Fix for bug with compare rule + if(is_array($element)){ + $onBlur = $element[0]->getAttribute('onBlur'); + $onChange = $element[0]->getAttribute('onChange'); + $element[0]->updateAttributes(array('onBlur' => $onBlur . $valFunc, + 'onChange' => $onChange . $valFunc)); + }else{ + //end of rough fix + $valFunc = 'validate_' . $this->_formName . '_' . $elementName . '(this)'; + $onBlur = $element->getAttribute('onBlur'); + $onChange = $element->getAttribute('onChange'); + $element->updateAttributes(array('onBlur' => $onBlur . $valFunc, 'onChange' => $onChange . $valFunc)); + //Rough Fix for bug with compare rule + } + //end of rough fix } // do not rely on frm function parameter, because htmlarea breaks it when overloading the onsubmit method $js .= ' Index: question/type/match/edit_match_form.php =================================================================== RCS file: /cvsroot/moodle/moodle/question/type/match/edit_match_form.php,v retrieving revision 1.8.2.4 diff -u -r1.8.2.4 edit_match_form.php --- question/type/match/edit_match_form.php 27 Oct 2008 02:33:28 -0000 1.8.2.4 +++ question/type/match/edit_match_form.php 8 Nov 2008 23:54:26 -0000 @@ -36,16 +36,22 @@ } else { $countsubquestions = 0; } + + $userprefrepeats=get_user_preferences($this->qtype().'_noanswers',0); + if($userprefrepeats==0){//fallback on default value + $userprefrepeats=QUESTION_NUMANS_START; + } if ($this->question->formoptions->repeatelements){ - $repeatsatstart = (QUESTION_NUMANS_START > ($countsubquestions + QUESTION_NUMANS_ADD))? - QUESTION_NUMANS_START : ($countsubquestions + QUESTION_NUMANS_ADD); + $repeatsatstart = ($countsubquestions > 0 )? + $countsubquestions+QUESTION_NUMANS_ADD : $userprefrepeats; } else { $repeatsatstart = $countsubquestions; } + $mform->setType('subanswer', PARAM_TEXT); $mform->setType('subquestion', PARAM_TEXT); - $this->repeat_elements($repeated, $repeatsatstart, array(), 'noanswers', 'addanswers', QUESTION_NUMANS_ADD, get_string('addmoreqblanks', 'qtype_match')); + $this->repeat_elements($repeated, $repeatsatstart, array(), 'oldnoanswers','noanswers', 'edoptgrp', 'edopthdr', 'addanswers', get_string('numberofblanks', 'qtype_match')); } Index: question/type/match/questiontype.php =================================================================== RCS file: /cvsroot/moodle/moodle/question/type/match/questiontype.php,v retrieving revision 1.32.2.5 diff -u -r1.32.2.5 questiontype.php --- question/type/match/questiontype.php 20 Aug 2008 09:46:03 -0000 1.32.2.5 +++ question/type/match/questiontype.php 8 Nov 2008 23:41:18 -0000 @@ -30,11 +30,12 @@ // $subquestions will be an array with subquestion ids $subquestions = array(); - + $countsubquestions=0; // Insert all the new question+answer pairs foreach ($question->subquestions as $key => $questiontext) { $answertext = $question->subanswers[$key]; if ($questiontext != '' || $answertext != '') { + $countsubquestions++; if ($subquestion = array_shift($oldsubquestions)) { // Existing answer, so reuse it $subquestion->questiontext = $questiontext; $subquestion->answertext = $answertext; @@ -63,7 +64,8 @@ $result->notice = get_string('nomatchinganswer', 'quiz', $questiontext); } } - + //save count of subquestions as user preferences + set_user_preference($this->name().'_noanswers', $countsubquestions); // delete old subquestions records if (!empty($oldsubquestions)) { foreach($oldsubquestions as $os) {