/** * @param MoodleQuickForm $mform */ function add_submit_buttons($mform) { $buttons = array(); $buttons[] =& $mform->createElement('submit', 'submitbutton', get_string('filter', 'local_mr')); $buttons[] =& $mform->createElement('submit', 'resetbutton', get_string('reset', 'local_mr')); $mform->addGroup($buttons, 'buttons', '', array(' '), false); $mform->registerNoSubmitButton('reset'); }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ function definition_inner(&$mform) { global $QTYPES; $this->qtypeobj =& $QTYPES[$this->qtype()]; $label = get_string("sharedwildcards", "qtype_datasetdependent"); $mform->addElement('hidden', 'initialcategory', 1); $html2 = $this->qtypeobj->print_dataset_definitions_category($this->question); $mform->insertElementBefore($mform->createElement('static', 'listcategory', $label, $html2), 'name'); $addfieldsname = 'updatecategory'; $addstring = get_string("updatecategory", "qtype_calculated"); $mform->registerNoSubmitButton($addfieldsname); $mform->insertElementBefore($mform->createElement('submit', $addfieldsname, $addstring), 'listcategory'); $repeated = array(); $repeated[] =& $mform->createElement('header', 'answerhdr', get_string('answerhdr', 'qtype_calculated', '{no}')); $repeated[] =& $mform->createElement('text', 'answers', get_string('correctanswerformula', 'quiz') . '=', array('size' => 50)); $repeatedoptions['answers']['type'] = PARAM_NOTAGS; $creategrades = get_grade_options(); $gradeoptions = $creategrades->gradeoptions; $repeated[] =& $mform->createElement('select', 'fraction', get_string('grade'), $gradeoptions); $repeatedoptions['fraction']['default'] = 0; $repeated[] =& $mform->createElement('text', 'tolerance', get_string('tolerance', 'qtype_calculated')); $repeatedoptions['tolerance']['type'] = PARAM_NUMBER; $repeatedoptions['tolerance']['default'] = 0.01; $repeated[] =& $mform->createElement('select', 'tolerancetype', get_string('tolerancetype', 'quiz'), $this->qtypeobj->tolerance_types()); $repeated[] =& $mform->createElement('select', 'correctanswerlength', get_string('correctanswershows', 'qtype_calculated'), range(0, 9)); $repeatedoptions['correctanswerlength']['default'] = 2; $answerlengthformats = array('1' => get_string('decimalformat', 'quiz'), '2' => get_string('significantfiguresformat', 'quiz')); $repeated[] =& $mform->createElement('select', 'correctanswerformat', get_string('correctanswershowsformat', 'qtype_calculated'), $answerlengthformats); $repeated[] =& $mform->createElement('htmleditor', 'feedback', get_string('feedback', 'quiz')); $repeatedoptions['feedback']['type'] = PARAM_RAW; if (isset($this->question->options)) { $count = count($this->question->options->answers); } else { $count = 0; } $repeatsatstart = $count + 1; $this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions, 'noanswers', 'addanswers', 1, get_string('addmoreanswerblanks', 'qtype_calculated')); $repeated = array(); $repeated[] =& $mform->createElement('header', 'unithdr', get_string('unithdr', 'qtype_numerical', '{no}')); $repeated[] =& $mform->createElement('text', 'unit', get_string('unit', 'quiz')); $mform->setType('unit', PARAM_NOTAGS); $repeated[] =& $mform->createElement('text', 'multiplier', get_string('multiplier', 'quiz')); $mform->setType('multiplier', PARAM_NUMBER); if (isset($this->question->options)) { $countunits = count($this->question->options->units); } else { $countunits = 0; } $repeatsatstart = $countunits + 1; $this->repeat_elements($repeated, $repeatsatstart, array(), 'nounits', 'addunits', 2, get_string('addmoreunitblanks', 'qtype_calculated', '{no}')); $firstunit =& $mform->getElement('multiplier[0]'); $firstunit->freeze(); $firstunit->setValue('1.0'); $firstunit->setPersistantFreeze(true); //hidden elements $mform->addElement('hidden', 'wizard', 'datasetdefinitions'); $mform->setType('wizard', PARAM_ALPHA); }
/** * definition_inner adds all specific fields to the form. * * @param MoodleQuickForm $mform (the form being built). */ protected function definition_inner($mform) { $mform->addElement('header', 'previewareaheader', get_string('previewareaheader', 'qtype_' . $this->qtype())); $mform->setExpanded('previewareaheader'); $mform->addElement('static', 'previewarea', '', get_string('previewareamessage', 'qtype_' . $this->qtype())); $mform->registerNoSubmitButton('refresh'); $mform->addElement('submit', 'refresh', get_string('refresh', 'qtype_' . $this->qtype())); $mform->addElement('filepicker', 'bgimage', get_string('bgimage', 'qtype_' . $this->qtype()), null, self::file_picker_options()); $mform->closeHeaderBefore('dropzoneheader'); // Add the draggable image fields & drop zones to the form. list($itemrepeatsatstart, $imagerepeats) = $this->get_drag_item_repeats(); $this->definition_draggable_items($mform, $itemrepeatsatstart); $this->definition_drop_zones($mform, $imagerepeats); $this->add_combined_feedback_fields(true); $this->add_interactive_settings(true, true); }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ function definition_inner(&$mform) { global $QTYPES; $this->qtypeobj =& $QTYPES[$this->qtype()]; $label = get_string("sharedwildcards", "qtype_datasetdependent"); $mform->addElement('hidden', 'initialcategory', 1); $html2 = $this->qtypeobj->print_dataset_definitions_category($this->question); $mform->insertElementBefore($mform->createElement('static', 'listcategory', $label, $html2), 'name'); $addfieldsname = 'updatecategory'; $addstring = get_string("updatecategory", "qtype_calculated"); $mform->registerNoSubmitButton($addfieldsname); $mform->insertElementBefore($mform->createElement('submit', $addfieldsname, $addstring), 'listcategory'); $creategrades = get_grade_options(); $this->add_per_answer_fields($mform, get_string('answerhdr', 'qtype_calculated', '{no}'), $creategrades->gradeoptions, 1, 1); $repeated = array(); $repeated[] =& $mform->createElement('header', 'unithdr', get_string('unithdr', 'qtype_numerical', '{no}')); $repeated[] =& $mform->createElement('text', 'unit', get_string('unit', 'quiz')); $mform->setType('unit', PARAM_NOTAGS); $repeated[] =& $mform->createElement('text', 'multiplier', get_string('multiplier', 'quiz')); $mform->setType('multiplier', PARAM_NUMBER); if (isset($this->question->options)) { $countunits = count($this->question->options->units); } else { $countunits = 0; } if ($this->question->formoptions->repeatelements) { $repeatsatstart = $countunits + 1; } else { $repeatsatstart = $countunits; } $this->repeat_elements($repeated, $repeatsatstart, array(), 'nounits', 'addunits', 2, get_string('addmoreunitblanks', 'qtype_calculated', '{no}')); if ($mform->elementExists('multiplier[0]')) { $firstunit =& $mform->getElement('multiplier[0]'); $firstunit->freeze(); $firstunit->setValue('1.0'); $firstunit->setPersistantFreeze(true); } //hidden elements $mform->addElement('hidden', 'synchronize', ''); if (isset($this->question->options) && isset($this->question->options->synchronize)) { $mform->setDefault("synchronize", $this->question->options->synchronize); } else { $mform->setDefault("synchronize", 0); } $mform->addElement('hidden', 'wizard', 'datasetdefinitions'); $mform->setType('wizard', PARAM_ALPHA); }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ function definition_inner(&$mform) { global $QTYPES; $this->qtypeobj =& $QTYPES[$this->qtype()]; // echo code left for testing period // echo "<p>question ".optional_param('multichoice', '', PARAM_RAW)." optional<pre>";print_r($this->question);echo "</pre></p>"; $label = get_string("sharedwildcards", "qtype_calculated"); $mform->addElement('hidden', 'initialcategory', 1); $mform->addElement('hidden', 'reload', 1); $mform->setType('initialcategory', PARAM_INT); // $html2 = $this->qtypeobj->print_dataset_definitions_category($this->question); $html2 = ""; $mform->insertElementBefore($mform->createElement('static', 'listcategory', $label, $html2), 'name'); if (isset($this->question->id)) { $mform->insertElementBefore($mform->createElement('static', 'initialname', get_string('questionstoredname', 'qtype_calculated'), $this->initialname), 'name'); } $addfieldsname = 'updatecategory'; $addstring = get_string("updatecategory", "qtype_calculated"); $mform->registerNoSubmitButton($addfieldsname); $this->editasmultichoice = 1; $mform->insertElementBefore($mform->createElement('submit', $addfieldsname, $addstring), 'listcategory'); $mform->registerNoSubmitButton('createoptionbutton'); $mform->addElement('hidden', 'multichoice', $this->editasmultichoice); $mform->setType('multichoice', PARAM_INT); // $mform->addElement('header', 'choicehdr',get_string('multichoicecalculatedquestion', 'qtype_calculated')); $menu = array(get_string('answersingleno', 'qtype_multichoice'), get_string('answersingleyes', 'qtype_multichoice')); $mform->addElement('select', 'single', get_string('answerhowmany', 'qtype_multichoice'), $menu); $mform->setDefault('single', 1); $mform->addElement('advcheckbox', 'shuffleanswers', get_string('shuffleanswers', 'qtype_multichoice'), null, null, array(0, 1)); $mform->addHelpButton('shuffleanswers', 'shuffleanswers', 'qtype_multichoice'); $mform->setDefault('shuffleanswers', 1); $numberingoptions = $QTYPES['multichoice']->get_numbering_styles(); $menu = array(); foreach ($numberingoptions as $numberingoption) { $menu[$numberingoption] = get_string('answernumbering' . $numberingoption, 'qtype_multichoice'); } $mform->addElement('select', 'answernumbering', get_string('answernumbering', 'qtype_multichoice'), $menu); $mform->setDefault('answernumbering', 'abc'); $creategrades = get_grade_options(); $this->add_per_answer_fields($mform, get_string('choiceno', 'qtype_multichoice', '{no}'), $creategrades->gradeoptionsfull, max(5, QUESTION_NUMANS_START)); $repeated = array(); // if ($this->editasmultichoice == 1){ $nounits = optional_param('nounits', 1, PARAM_INT); $mform->addElement('hidden', 'nounits', $nounits); $mform->setType('nounits', PARAM_INT); $mform->setConstants(array('nounits' => $nounits)); for ($i = 0; $i < $nounits; $i++) { $mform->addElement('hidden', 'unit' . "[{$i}]", optional_param('unit' . "[{$i}]", '', PARAM_NOTAGS)); $mform->setType('unit' . "[{$i}]", PARAM_NOTAGS); $mform->addElement('hidden', 'multiplier' . "[{$i}]", optional_param('multiplier' . "[{$i}]", '', PARAM_NUMBER)); $mform->setType('multiplier' . "[{$i}]", PARAM_NUMBER); } $mform->setType('addunits', 'hidden'); $mform->addElement('header', 'overallfeedbackhdr', get_string('overallfeedback', 'qtype_multichoice')); foreach (array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback') as $feedbackname) { $mform->addElement('editor', $feedbackname, get_string($feedbackname, 'qtype_multichoice'), null, $this->editoroptions); $mform->setType($feedbackname, PARAM_RAW); } //hidden elements $mform->addElement('hidden', 'synchronize', ''); $mform->setType('synchronize', PARAM_INT); if (isset($this->question->options) && isset($this->question->options->synchronize)) { $mform->setDefault("synchronize", $this->question->options->synchronize); } else { $mform->setDefault("synchronize", 0); } $mform->addElement('hidden', 'wizard', 'datasetdefinitions'); $mform->setType('wizard', PARAM_ALPHA); }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ protected function definition_inner($mform) { $strquestionlabel = $this->qtypeobj->comment_header($this->nonemptyanswer); $label = get_string("sharedwildcards", "qtype_calculated"); $mform->addElement('hidden', 'synchronize', 0); $mform->addElement('hidden', 'initialcategory', 1); $mform->setType('synchronize', PARAM_BOOL); $mform->setType('initialcategory', PARAM_INT); $mform->addElement('hidden', 'reload', 1); $mform->setType('reload', PARAM_INT); $addfieldsname = 'updatequestion value'; $addstring = get_string("updatecategory", "qtype_calculated"); $mform->registerNoSubmitButton($addfieldsname); $this->add_per_answer_fields($mform, get_string('answerhdr', 'qtype_calculated', '{no}'), question_bank::fraction_options(), 1, 1); $this->add_unit_options($mform, $this); $this->add_unit_fields($mform, $this); $this->add_interactive_settings(); $label = "<div class='mdl-align'></div><div class='mdl-align'>" . get_string('wildcardrole', 'qtype_calculatedsimple') . "</div>"; $mform->addElement('html', "<div class='mdl-align'> </div>"); // Explaining the role of datasets so other strings can be shortened. $mform->addElement('html', $label); $mform->addElement('submit', 'analyzequestion', get_string('findwildcards', 'qtype_calculatedsimple')); $mform->registerNoSubmitButton('analyzequestion'); $mform->closeHeaderBefore('analyzequestion'); $this->wizarddisplay = optional_param('analyzequestion', false, PARAM_BOOL); if ($this->maxnumber != -1) { $this->noofitems = $this->maxnumber; } else { $this->noofitems = 0; } if (!empty($this->datasetdefs)) { // So there are some datadefs. // We put them on the page. $key = 0; $mform->addElement('header', 'additemhdr', get_string('wildcardparam', 'qtype_calculatedsimple')); $idx = 1; if (!empty($this->datasetdefs)) { // Unnecessary test. $j = $this->noofitems * count($this->datasetdefs) + 1; // foreach ($this->datasetdefs as $defkey => $datasetdef) { $mform->addElement('static', "na[{$j}]", get_string('param', 'qtype_calculated', $datasetdef->name)); $this->qtypeobj->custom_generator_tools_part($mform, $idx, $j); $mform->addElement('hidden', "datasetdef[{$idx}]"); $mform->setType("datasetdef[{$idx}]", PARAM_RAW); $mform->addElement('hidden', "defoptions[{$idx}]"); $mform->setType("defoptions[{$idx}]", PARAM_RAW); $idx++; $mform->addElement('static', "divider[{$j}]", '', '<hr />'); $j++; } } // This should be done before the elements are created and stored as $this->formdata. // Fill out all data sets and also the fields for the next item to add. /*Here we do already the values error analysis so that * we could force all wild cards values display if there is an error in values. * as using a , in a number */ $this->numbererrors = array(); if (!empty($this->datasetdefs)) { $j = $this->noofitems * count($this->datasetdefs); for ($itemnumber = $this->noofitems; $itemnumber >= 1; $itemnumber--) { $data = array(); $numbererrors = array(); $comment = new stdClass(); $comment->stranswers = array(); $comment->outsidelimit = false; $comment->answers = array(); foreach ($this->datasetdefs as $defid => $datasetdef) { if (isset($datasetdef->items[$itemnumber])) { $this->formdata["definition[{$j}]"] = $defid; $this->formdata["itemid[{$j}]"] = $datasetdef->items[$itemnumber]->id; $data[$datasetdef->name] = $datasetdef->items[$itemnumber]->value; $this->formdata["number[{$j}]"] = $number = $datasetdef->items[$itemnumber]->value; if (!is_numeric($number)) { $a = new stdClass(); $a->name = '{' . $datasetdef->name . '}'; $a->value = $datasetdef->items[$itemnumber]->value; if (stristr($number, ',')) { $this->numbererrors["number[{$j}]"] = get_string('nocommaallowed', 'qtype_calculated'); $numbererrors .= $this->numbererrors['number[' . $j . ']'] . "<br />"; } else { $this->numbererrors["number[{$j}]"] = get_string('notvalidnumber', 'qtype_calculated', $a); $numbererrors .= $this->numbererrors['number[' . $j . ']'] . "<br />"; } } else { if (stristr($number, 'x')) { // Hexa will pass the test. $a = new stdClass(); $a->name = '{' . $datasetdef->name . '}'; $a->value = $datasetdef->items[$itemnumber]->value; $this->numbererrors['number[' . $j . ']'] = get_string('hexanotallowed', 'qtype_calculated', $a); $numbererrors .= $this->numbererrors['number[' . $j . ']'] . "<br />"; } else { if (is_nan($number)) { $a = new stdClass(); $a->name = '{' . $datasetdef->name . '}'; $a->value = $datasetdef->items[$itemnumber]->value; $this->numbererrors["number[{$j}]"] = get_string('notvalidnumber', 'qtype_calculated', $a); $numbererrors .= $this->numbererrors['number[' . $j . ']'] . "<br />"; } } } } $j--; } if ($this->noofitems != 0) { if (empty($numbererrors)) { if (!isset($this->question->id)) { $this->question->id = 0; } $this->question->questiontext = !empty($this->question->questiontext) ? $this->question->questiontext : ''; $comment = $this->qtypeobj->comment_on_datasetitems($this->qtypeobj, $this->question->id, $this->question->questiontext, $this->nonemptyanswer, $data, $itemnumber); if ($comment->outsidelimit) { $this->outsidelimit = $comment->outsidelimit; } $totalcomment = ''; foreach ($this->nonemptyanswer as $key => $answer) { $totalcomment .= $comment->stranswers[$key] . '<br/>'; } $this->formdata['answercomment[' . $itemnumber . ']'] = $totalcomment; } } } $this->formdata['selectdelete'] = '1'; $this->formdata['selectadd'] = '1'; $j = $this->noofitems * count($this->datasetdefs) + 1; $data = array(); // Data for comment_on_datasetitems later. $idx = 1; foreach ($this->datasetdefs as $defid => $datasetdef) { $this->formdata["datasetdef[{$idx}]"] = $defid; $idx++; } $this->formdata = $this->qtypeobj->custom_generator_set_data($this->datasetdefs, $this->formdata); } $addoptions = array(); $addoptions['1'] = '1'; for ($i = 10; $i <= 100; $i += 10) { $addoptions["{$i}"] = "{$i}"; } $showoptions = array(); $showoptions['1'] = '1'; $showoptions['2'] = '2'; $showoptions['5'] = '5'; for ($i = 10; $i <= 100; $i += 10) { $showoptions["{$i}"] = "{$i}"; } $mform->closeHeaderBefore('additemhdr'); $addgrp = array(); $addgrp[] = $mform->createElement('submit', 'addbutton', get_string('generatenewitemsset', 'qtype_calculatedsimple')); $addgrp[] = $mform->createElement('select', "selectadd", '', $addoptions); $addgrp[] = $mform->createElement('static', "stat", '', get_string('newsetwildcardvalues', 'qtype_calculatedsimple')); $mform->addGroup($addgrp, 'addgrp', '', ' ', false); $mform->registerNoSubmitButton('addbutton'); $mform->closeHeaderBefore('addgrp'); $addgrp1 = array(); $addgrp1[] = $mform->createElement('submit', 'showbutton', get_string('showitems', 'qtype_calculatedsimple')); $addgrp1[] = $mform->createElement('select', "selectshow", '', $showoptions); $addgrp1[] = $mform->createElement('static', "stat", '', get_string('setwildcardvalues', 'qtype_calculatedsimple')); $mform->addGroup($addgrp1, 'addgrp1', '', ' ', false); $mform->registerNoSubmitButton('showbutton'); $mform->closeHeaderBefore('addgrp1'); $mform->addElement('static', "divideradd", '', ''); if ($this->noofitems == 0) { $mform->addElement('static', 'warningnoitems', '', '<span class="error">' . get_string('youmustaddatleastonevalue', 'qtype_calculatedsimple') . '</span>'); $mform->closeHeaderBefore('warningnoitems'); } else { $mform->addElement('header', 'additemhdr1', get_string('wildcardvalues', 'qtype_calculatedsimple')); $mform->closeHeaderBefore('additemhdr1'); if (!empty($this->numbererrors) || $this->outsidelimit) { $mform->addElement('static', "alert", '', '<span class="error">' . get_string('useadvance', 'qtype_calculatedsimple') . '</span>'); } $mform->addElement('submit', 'updatedatasets', get_string('updatewildcardvalues', 'qtype_calculatedsimple')); $mform->registerNoSubmitButton('updatedatasets'); $mform->setAdvanced("updatedatasets", true); // ...--------------------------------------------------------------. $j = $this->noofitems * count($this->datasetdefs); $k = optional_param('selectshow', 1, PARAM_INT); for ($i = $this->noofitems; $i >= 1; $i--) { foreach ($this->datasetdefs as $defkey => $datasetdef) { if ($k > 0 || $this->outsidelimit || !empty($this->numbererrors)) { $mform->addElement('text', "number[{$j}]", get_string('wildcard', 'qtype_calculatedsimple', $datasetdef->name)); $mform->setAdvanced("number[{$j}]", true); if (!empty($this->numbererrors['number[' . $j . ']'])) { $mform->addElement('static', "numbercomment[{$j}]", '', '<span class="error">' . $this->numbererrors['number[' . $j . ']'] . '</span>'); $mform->setAdvanced("numbercomment[{$j}]", true); } } else { $mform->addElement('hidden', "number[{$j}]", get_string('wildcard', 'qtype_calculatedsimple', $datasetdef->name)); } $mform->setType("number[{$j}]", PARAM_RAW); // This parameter will be validated in validation(). $mform->addElement('hidden', "itemid[{$j}]"); $mform->setType("itemid[{$j}]", PARAM_INT); $mform->addElement('hidden', "definition[{$j}]"); $mform->setType("definition[{$j}]", PARAM_NOTAGS); $j--; } if (!empty($strquestionlabel) && ($k > 0 || $this->outsidelimit || !empty($this->numbererrors))) { $mform->addElement('static', "answercomment[{$i}]", "<b>" . get_string('setno', 'qtype_calculatedsimple', $i) . "</b> " . $strquestionlabel); } if ($k > 0 || $this->outsidelimit || !empty($this->numbererrors)) { $mform->addElement('static', "divider1[{$j}]", '', '<hr />'); } $k--; } } } else { $mform->addElement('static', 'warningnowildcards', '', '<span class="error">' . get_string('atleastonewildcard', 'qtype_calculatedsimple') . '</span>'); $mform->closeHeaderBefore('warningnowildcards'); } // ...----------------------------------------------------------------------. // Non standard name for button element needed so not using add_action_buttons. // Hidden elements. $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'courseid'); $mform->setType('courseid', PARAM_INT); $mform->setDefault('courseid', 0); $mform->addElement('hidden', 'cmid'); $mform->setType('cmid', PARAM_INT); $mform->setDefault('cmid', 0); if (!empty($this->question->id)) { if ($this->question->formoptions->cansaveasnew) { $mform->addElement('header', 'additemhdr', get_string('converttocalculated', 'qtype_calculatedsimple')); $mform->closeHeaderBefore('additemhdr'); $mform->addElement('checkbox', 'convert', '', get_string('willconverttocalculated', 'qtype_calculatedsimple')); $mform->setDefault('convert', 0); } } }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ protected function definition_inner($mform) { $this->qtypeobj = question_bank::get_qtype($this->qtype()); $label = get_string('sharedwildcards', 'qtype_calculated'); $mform->addElement('hidden', 'initialcategory', 1); $mform->addElement('hidden', 'reload', 1); $mform->setType('initialcategory', PARAM_INT); $html2 = $this->qtypeobj->print_dataset_definitions_category($this->question); $mform->insertElementBefore( $mform->createElement('static', 'listcategory', $label, $html2), 'name'); if (isset($this->question->id)) { $mform->insertElementBefore($mform->createElement('static', 'initialname', get_string('questionstoredname', 'qtype_calculated'), $this->initialname), 'name'); }; $addfieldsname = 'updatecategory'; $addstring = get_string('updatecategory', 'qtype_calculated'); $mform->registerNoSubmitButton($addfieldsname); $mform->insertElementBefore( $mform->createElement('submit', $addfieldsname, $addstring), 'listcategory'); $mform->registerNoSubmitButton('createoptionbutton'); //editing as regular $mform->setType('single', PARAM_INT); $mform->addElement('hidden', 'shuffleanswers', '1'); $mform->setType('shuffleanswers', PARAM_INT); $mform->addElement('hidden', 'answernumbering', 'abc'); $mform->setType('answernumbering', PARAM_SAFEDIR); $this->add_per_answer_fields($mform, get_string('answerhdr', 'qtype_calculated', '{no}'), question_bank::fraction_options(), 1, 1); $repeated = array(); $this->add_unit_options($mform, $this); $this->add_unit_fields($mform, $this); $this->add_interactive_settings(); // Hidden elements $mform->addElement('hidden', 'synchronize', ''); $mform->setType('synchronize', PARAM_INT); $mform->addElement('hidden', 'wizard', 'datasetdefinitions'); $mform->setType('wizard', PARAM_ALPHA); }
/** * Add the form elements defining one PRT node. * @param string $prtname the name of the PRT. * @param string $name the name of the node. * @param array $nextnodechoices the available choices for the next node. * @param bool $deletable whether the user is allowed to delete this node. * @param MoodleQuickForm $mform the form being assembled. */ protected function definition_prt_node($prtname, $name, $nextnodechoices, $deletable, MoodleQuickForm $mform) { $nodekey = $name - 1; unset($nextnodechoices[$nodekey]); $nodegroup = array(); $nodegroup[] = $mform->createElement('select', $prtname . 'answertest[' . $nodekey . ']', stack_string('answertest'), $this->answertestchoices); $nodegroup[] = $mform->createElement('text', $prtname . 'sans[' . $nodekey . ']', stack_string('sans'), array('size' => 15)); $nodegroup[] = $mform->createElement('text', $prtname . 'tans[' . $nodekey . ']', stack_string('tans'), array('size' => 15)); $nodegroup[] = $mform->createElement('text', $prtname . 'testoptions[' . $nodekey . ']', stack_string('testoptions'), array('size' => 5)); $nodegroup[] = $mform->createElement('selectyesno', $prtname . 'quiet[' . $nodekey . ']', stack_string('quiet')); $mform->addGroup($nodegroup, $prtname . 'node[' . $nodekey . ']', html_writer::tag('b', stack_string('nodex', $name)), null, false); $mform->addHelpButton($prtname . 'node[' . $nodekey . ']', 'nodehelp', 'qtype_stack'); $mform->setType($prtname . 'sans[' . $nodekey . ']', PARAM_RAW); $mform->setType($prtname . 'tans[' . $nodekey . ']', PARAM_RAW); $mform->setType($prtname . 'testoptions[' . $nodekey . ']', PARAM_RAW); // Create the section of the form for each node - the branches. foreach (array('true', 'false') as $branch) { $branchgroup = array(); $branchgroup[] = $mform->createElement('select', $prtname . $branch . 'scoremode[' . $nodekey . ']', stack_string('scoremode'), $this->scoremodechoices); if ($nodekey > 0) { if ($branch === 'true') { $mform->setDefault($prtname . $branch . 'scoremode[' . $nodekey . ']', '+'); } else { $mform->setDefault($prtname . $branch . 'scoremode[' . $nodekey . ']', '-'); } } $branchgroup[] = $mform->createElement('text', $prtname . $branch . 'score[' . $nodekey . ']', stack_string('score'), array('size' => 2)); $mform->setDefault($prtname . $branch . 'score[' . $nodekey . ']', (int) ($branch === 'true' && $nodekey == 0)); $branchgroup[] = $mform->createElement('text', $prtname . $branch . 'penalty[' . $nodekey . ']', stack_string('penalty'), array('size' => 2)); $branchgroup[] = $mform->createElement('select', $prtname . $branch . 'nextnode[' . $nodekey . ']', stack_string('next'), $nextnodechoices); $branchgroup[] = $mform->createElement('text', $prtname . $branch . 'answernote[' . $nodekey . ']', stack_string('answernote'), array('size' => 10)); $mform->setDefault($prtname . $branch . 'answernote[' . $nodekey . ']', stack_string('answernotedefault' . $branch, array('prtname' => $prtname, 'nodename' => $name))); $mform->addGroup($branchgroup, $prtname . 'nodewhen' . $branch . '[' . $nodekey . ']', stack_string('nodexwhen' . $branch, $name), null, false); $mform->addHelpButton($prtname . 'nodewhen' . $branch . '[' . $nodekey . ']', $branch . 'branch', 'qtype_stack'); $mform->setType($prtname . $branch . 'score[' . $nodekey . ']', PARAM_RAW); $mform->setType($prtname . $branch . 'penalty[' . $nodekey . ']', PARAM_RAW); $mform->setType($prtname . $branch . 'answernote[' . $nodekey . ']', PARAM_RAW); $mform->addElement('editor', $prtname . $branch . 'feedback[' . $nodekey . ']', stack_string('nodex' . $branch . 'feedback', $name), array('rows' => 1), $this->editoroptions); $mform->addHelpButton($prtname . $branch . 'feedback[' . $nodekey . ']', 'branchfeedback', 'qtype_stack'); } if ($deletable) { $mform->addElement('submit', $prtname . 'nodedelete' . $nodekey, stack_string('nodexdelete', $name)); $mform->registerNoSubmitButton($prtname . 'nodedelete' . $nodekey); } }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ function definition_inner(&$mform) { global $QTYPES; $this->qtypeobj =& $QTYPES[$this->qtype()]; $strquestionlabel = $this->qtypeobj->comment_header($this->nonemptyanswer); $label = get_string("sharedwildcards", "qtype_datasetdependent"); $mform->addElement('hidden', 'initialcategory', 1); $mform->addElement('hidden', 'reload', 1); $addfieldsname = 'updatequestion value'; $addstring = get_string("updatecategory", "qtype_calculated"); $mform->registerNoSubmitButton($addfieldsname); //put a submit button to stop supplementary answers on update answers parameters // $mform->insertElementBefore( $mform->createElement('submit', $addfieldsname, $addstring),'listcategory'); $creategrades = get_grade_options(); $this->add_per_answer_fields($mform, get_string('answerhdr', 'qtype_calculated', '{no}'), $creategrades->gradeoptions, 1, 1); $repeated = array(); $repeated[] =& $mform->createElement('header', 'unithdr', get_string('unithdr', 'qtype_numerical', '{no}')); $repeated[] =& $mform->createElement('text', 'unit', get_string('unit', 'quiz')); $mform->setType('unit', PARAM_NOTAGS); $repeated[] =& $mform->createElement('text', 'multiplier', get_string('multiplier', 'quiz')); $mform->setType('multiplier', PARAM_NUMBER); if (isset($this->question->options)) { $countunits = count($this->question->options->units); } else { $countunits = 0; } if ($this->question->formoptions->repeatelements) { $repeatsatstart = $countunits + 1; } else { $repeatsatstart = $countunits; } $this->repeat_elements($repeated, $repeatsatstart, array(), 'nounits', 'addunits', 2, get_string('addmoreunitblanks', 'qtype_calculated', '{no}')); if ($mform->elementExists('multiplier[0]')) { $firstunit =& $mform->getElement('multiplier[0]'); $firstunit->freeze(); $firstunit->setValue('1.0'); $firstunit->setPersistantFreeze(true); } //hidden elements // $mform->addElement('hidden', 'wizard', 'datasetdefinitions'); // $mform->setType('wizard', PARAM_ALPHA); // $mform->addElement('header', '', ''); $label = "<div class='mdl-align'></div><div class='mdl-align'>" . get_string('wildcardrole', 'qtype_calculatedsimple') . "</div>"; $mform->addElement('html', "<div class='mdl-align'> </div>"); $mform->addElement('html', $label); // explaining the role of datasets so other strings can be shortened $mform->addElement('submit', 'analyzequestion', get_string('findwildcards', 'qtype_calculatedsimple')); $mform->registerNoSubmitButton('analyzequestion'); $mform->closeHeaderBefore('analyzequestion'); if ("" != optional_param('analyzequestion', '', PARAM_RAW)) { $this->wizarddisplay = true; } else { $this->wizwarddisplay = false; } if ($this->maxnumber != -1) { $this->noofitems = $this->maxnumber; } else { $this->noofitems = 0; } if (!empty($this->datasetdefs)) { //So there are some datadefs // we put them on the page $key = 0; $mform->addElement('header', 'additemhdr', get_string('wildcardparam', 'qtype_calculatedsimple')); $idx = 1; if (!empty($this->datasetdefs)) { // unnecessary test $j = $this->noofitems * count($this->datasetdefs) + 1; // foreach ($this->datasetdefs as $defkey => $datasetdef) { $mform->addElement('static', "na[{$j}]", get_string('param', 'qtype_datasetdependent', $datasetdef->name)); $this->qtypeobj->custom_generator_tools_part($mform, $idx, $j); $mform->addElement('hidden', "datasetdef[{$idx}]"); $mform->setType("datasetdef[{$idx}]", PARAM_RAW); $idx++; $mform->addElement('static', "divider[{$j}]", '', '<hr />'); $j++; } } //this should be done before the elements are created and stored as $this->formdata ; //fill out all data sets and also the fields for the next item to add. /*Here we do already the values error analysis so that * we could force all wild cards values display if there is an error in values. * as using a , in a number */ $this->numbererrors = array(); if (!empty($this->datasetdefs)) { $j = $this->noofitems * count($this->datasetdefs); for ($itemnumber = $this->noofitems; $itemnumber >= 1; $itemnumber--) { $data = array(); $numbererrors = array(); $comment = new stdClass(); $comment->stranswers = array(); $comment->outsidelimit = false; $comment->answers = array(); foreach ($this->datasetdefs as $defid => $datasetdef) { if (isset($datasetdef->items[$itemnumber])) { $this->formdata["definition[{$j}]"] = $defid; $this->formdata["itemid[{$j}]"] = $datasetdef->items[$itemnumber]->id; $data[$datasetdef->name] = $datasetdef->items[$itemnumber]->value; $this->formdata["number[{$j}]"] = $number = $datasetdef->items[$itemnumber]->value; if (!is_numeric($number)) { $a = new stdClass(); $a->name = '{' . $datasetdef->name . '}'; $a->value = $datasetdef->items[$itemnumber]->value; if (stristr($number, ',')) { $this->numbererrors["number[{$j}]"] = get_string('nocommaallowed', 'qtype_datasetdependent'); $numbererrors .= $this->numbererrors['number[' . $j . ']'] . "<br />"; } else { $this->numbererrors["number[{$j}]"] = get_string('notvalidnumber', 'qtype_datasetdependent', $a); $numbererrors .= $this->numbererrors['number[' . $j . ']'] . "<br />"; //$comment->outsidelimit = false ; } } else { if (stristr($number, 'x')) { // hexa will pass the test $a = new stdClass(); $a->name = '{' . $datasetdef->name . '}'; $a->value = $datasetdef->items[$itemnumber]->value; $this->numbererrors['number[' . $j . ']'] = get_string('hexanotallowed', 'qtype_datasetdependent', $a); $numbererrors .= $this->numbererrors['number[' . $j . ']'] . "<br />"; } else { if (is_nan($number)) { $a = new stdClass(); $a->name = '{' . $datasetdef->name . '}'; $a->value = $datasetdef->items[$itemnumber]->value; $this->numbererrors["number[{$j}]"] = get_string('notvalidnumber', 'qtype_datasetdependent', $a); $numbererrors .= $this->numbererrors['number[' . $j . ']'] . "<br />"; // $val = 1.0 ; } } } } $j--; } if ($this->noofitems != 0) { if (empty($numbererrors)) { if (!isset($question->id)) { $question->id = 0; } $comment = $this->qtypeobj->comment_on_datasetitems($question->id, $this->nonemptyanswer, $data, $itemnumber); //$this-> if ($comment->outsidelimit) { $this->outsidelimit = $comment->outsidelimit; } $totalcomment = ''; foreach ($this->nonemptyanswer as $key => $answer) { $totalcomment .= $comment->stranswers[$key] . '<br/>'; } $this->formdata['answercomment[' . $itemnumber . ']'] = $totalcomment; } } } $this->formdata['selectdelete'] = '1'; $this->formdata['selectadd'] = '1'; $j = $this->noofitems * count($this->datasetdefs) + 1; $data = array(); // data for comment_on_datasetitems later $idx = 1; foreach ($this->datasetdefs as $defid => $datasetdef) { $this->formdata["datasetdef[{$idx}]"] = $defid; $idx++; } $this->formdata = $this->qtypeobj->custom_generator_set_data($this->datasetdefs, $this->formdata); } $addoptions = array(); $addoptions['1'] = '1'; for ($i = 10; $i <= 100; $i += 10) { $addoptions["{$i}"] = "{$i}"; } $showoptions = array(); $showoptions['1'] = '1'; $showoptions['2'] = '2'; $showoptions['5'] = '5'; for ($i = 10; $i <= 100; $i += 10) { $showoptions["{$i}"] = "{$i}"; } $mform->closeHeaderBefore('additemhdr'); $addgrp = array(); $addgrp[] =& $mform->createElement('submit', 'addbutton', get_string('generatenewitemsset', 'qtype_calculatedsimple')); $addgrp[] =& $mform->createElement('select', "selectadd", '', $addoptions); $addgrp[] =& $mform->createElement('static', "stat", '', get_string('newsetwildcardvalues', 'qtype_calculatedsimple')); $mform->addGroup($addgrp, 'addgrp', '', ' ', false); $mform->registerNoSubmitButton('addbutton'); $mform->closeHeaderBefore('addgrp'); $addgrp1 = array(); $addgrp1[] =& $mform->createElement('submit', 'showbutton', get_string('showitems', 'qtype_calculatedsimple')); $addgrp1[] =& $mform->createElement('select', "selectshow", '', $showoptions); $addgrp1[] =& $mform->createElement('static', "stat", '', get_string('setwildcardvalues', 'qtype_calculatedsimple')); $mform->addGroup($addgrp1, 'addgrp1', '', ' ', false); $mform->registerNoSubmitButton('showbutton'); $mform->closeHeaderBefore('addgrp1'); $mform->addElement('static', "divideradd", '', ''); if ($this->noofitems == 0) { $mform->addElement('static', 'warningnoitems', '', '<span class="error">' . get_string('youmustaddatleastonevalue', 'qtype_calculatedsimple') . '</span>'); $mform->closeHeaderBefore('warningnoitems'); } else { $mform->addElement('header', 'additemhdr1', get_string('wildcardvalues', 'qtype_calculatedsimple')); $mform->closeHeaderBefore('additemhdr1'); // $mform->addElement('header', '', get_string('itemno', 'qtype_datasetdependent', "")); if (!empty($this->numbererrors) || $this->outsidelimit) { $mform->addElement('static', "alert", '', '<span class="error">' . get_string('useadvance', 'qtype_calculatedsimple') . '</span>'); } $mform->addElement('submit', 'updatedatasets', get_string('updatewildcardvalues', 'qtype_calculatedsimple')); $mform->registerNoSubmitButton('updatedatasets'); $mform->setAdvanced("updatedatasets", true); //------------------------------------------------------------------------------------------------------------------------------ $j = $this->noofitems * count($this->datasetdefs); $k = 1; if ("" != optional_param('selectshow')) { $k = optional_param('selectshow'); } for ($i = $this->noofitems; $i >= 1; $i--) { foreach ($this->datasetdefs as $defkey => $datasetdef) { if ($k > 0 || $this->outsidelimit || !empty($this->numbererrors)) { $mform->addElement('text', "number[{$j}]", get_string('wildcard', 'qtype_calculatedsimple', $datasetdef->name)); $mform->setAdvanced("number[{$j}]", true); if (!empty($this->numbererrors['number[' . $j . ']'])) { $mform->addElement('static', "numbercomment[{$j}]", '', '<span class="error">' . $this->numbererrors['number[' . $j . ']'] . '</span>'); $mform->setAdvanced("numbercomment[{$j}]", true); } } else { $mform->addElement('hidden', "number[{$j}]", get_string('wildcard', 'qtype_calculatedsimple', $datasetdef->name)); } $mform->setType("number[{$j}]", PARAM_NUMBER); $mform->addElement('hidden', "itemid[{$j}]"); $mform->setType("itemid[{$j}]", PARAM_INT); $mform->addElement('hidden', "definition[{$j}]"); $mform->setType("definition[{$j}]", PARAM_NOTAGS); $j--; } if (!empty($strquestionlabel) && ($k > 0 || $this->outsidelimit || !empty($this->numbererrors))) { // $repeated[] =& $mform->addElement('static', "answercomment[$i]", $strquestionlabel); $mform->addElement('static', "answercomment[{$i}]", "<b>" . get_string('setno', 'qtype_calculatedsimple', $i) . "</b> " . $strquestionlabel); } if ($k > 0 || $this->outsidelimit || !empty($this->numbererrors)) { $mform->addElement('static', "divider1[{$j}]", '', '<hr />'); } $k--; } } // if ($this->outsidelimit){ // $mform->addElement('static','outsidelimit','',''); // } } else { $mform->addElement('static', 'warningnowildcards', '', '<span class="error">' . get_string('atleastonewildcard', 'qtype_calculatedsimple') . '</span>'); $mform->closeHeaderBefore('warningnowildcards'); } //------------------------------------------------------------------------------------------------------------------------------ //non standard name for button element needed so not using add_action_buttons //hidden elements $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'courseid'); $mform->setType('courseid', PARAM_INT); $mform->setDefault('courseid', 0); $mform->addElement('hidden', 'cmid'); $mform->setType('cmid', PARAM_INT); $mform->setDefault('cmid', 0); if (!empty($this->question->id)) { if ($this->question->formoptions->cansaveasnew) { $mform->addElement('header', 'additemhdr', get_string('converttocalculated', 'qtype_calculatedsimple')); $mform->closeHeaderBefore('additemhdr'); $mform->addElement('checkbox', 'convert', '', get_string('willconverttocalculated', 'qtype_calculatedsimple')); $mform->setDefault('convert', 0); } } // $mform->addElement('hidden', 'wizard', 'edit_calculatedsimple'); // $mform->setType('wizard', PARAM_ALPHA); /* $mform->addElement('hidden', 'returnurl'); $mform->setType('returnurl', PARAM_LOCALURL); $mform->setDefault('returnurl', 0); */ }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ function definition_inner(&$mform) { global $QTYPES; $this->qtypeobj =& $QTYPES[$this->qtype()]; $label = get_string('sharedwildcards', 'qtype_calculated'); $mform->addElement('hidden', 'initialcategory', 1); $mform->addElement('hidden', 'reload', 1); $mform->setType('initialcategory', PARAM_INT); $html2 = $this->qtypeobj->print_dataset_definitions_category($this->question); $mform->insertElementBefore($mform->createElement('static', 'listcategory', $label, $html2), 'name'); if (isset($this->question->id)) { $mform->insertElementBefore($mform->createElement('static', 'initialname', get_string('questionstoredname', 'qtype_calculated'), $this->initialname), 'name'); } $addfieldsname = 'updatecategory'; $addstring = get_string("updatecategory", "qtype_calculated"); $mform->registerNoSubmitButton($addfieldsname); $mform->insertElementBefore($mform->createElement('submit', $addfieldsname, $addstring), 'listcategory'); $mform->registerNoSubmitButton('createoptionbutton'); //editing as regular $mform->setType('single', PARAM_INT); $mform->addElement('hidden', 'shuffleanswers', '1'); $mform->setType('shuffleanswers', PARAM_INT); $mform->addElement('hidden', 'answernumbering', 'abc'); $mform->setType('answernumbering', PARAM_SAFEDIR); $creategrades = get_grade_options(); $this->add_per_answer_fields($mform, get_string('answerhdr', 'qtype_calculated', '{no}'), $creategrades->gradeoptions, 1, 1); $repeated = array(); $QTYPES['numerical']->add_units_options($mform, $this); $QTYPES['numerical']->add_units_elements($mform, $this); //hidden elements $mform->addElement('hidden', 'synchronize', ''); $mform->setType('synchronize', PARAM_INT); $mform->addElement('hidden', 'wizard', 'datasetdefinitions'); $mform->setType('wizard', PARAM_ALPHA); }
/** * method to add choice options to the form * * @param MoodleQuickForm $mform form * @param unknown $choice choice (new (negative id) or existing) */ private function add_choice_group(MoodleQuickForm $mform, $choice) { $elemprefix = 'choices_' . $choice->id . '_'; $mform->addElement('hidden', $elemprefix . 'id', $choice->id); // Save the record's id. $mform->setType($elemprefix . 'id', PARAM_INT); $elementname = 'fieldset_edit_choice' . $choice->id; $mform->addElement('header', $elementname, get_string('edit_choice', self::MOD_NAME, $choice->title)); $mform->insertElementBefore($mform->removeElement($elementname, false), self::CHOICE_PLACEHOLDER_IDENTIFIER); $elementname = $elemprefix . 'title'; $mform->addElement('text', $elementname, get_string('choice_title', self::MOD_NAME)); $mform->setDefault($elementname, $choice->title); $mform->setType($elementname, PARAM_TEXT); $mform->addHelpButton($elementname, 'choice_title', self::MOD_NAME); $mform->insertElementBefore($mform->removeElement($elementname, false), self::CHOICE_PLACEHOLDER_IDENTIFIER); $mform->addRule($elementname, $this->msgerrorrequired, 'required', null, 'server'); $elementname = $elemprefix . 'explanation'; $mform->addElement('text', $elementname, get_string('choice_explanation', self::MOD_NAME)); $mform->insertElementBefore($mform->removeElement($elementname, false), self::CHOICE_PLACEHOLDER_IDENTIFIER); $mform->setDefault($elementname, $choice->explanation); $mform->setType($elementname, PARAM_TEXT); $elementname = $elemprefix . 'maxsize'; $mform->addElement('text', $elementname, get_string('choice_maxsize', self::MOD_NAME)); $mform->insertElementBefore($mform->removeElement($elementname, false), self::CHOICE_PLACEHOLDER_IDENTIFIER); $mform->setDefault($elementname, $choice->maxsize); $mform->setType($elementname, PARAM_INT); $mform->addRule($elementname, $this->msgerrorrequired, 'required', null, 'server'); $elementname = $elemprefix . 'active'; $checkbox = $mform->addElement('advcheckbox', $elementname, get_string('choice_active', self::MOD_NAME), null, null, array(0, 1)); $mform->insertElementBefore($mform->removeElement($elementname, false), self::CHOICE_PLACEHOLDER_IDENTIFIER); $mform->setDefault($elementname, $choice->active); $mform->addHelpButton($elementname, 'choice_active', self::MOD_NAME); $elementname = self::DELETE_CHOICE_ACTION . $choice->id; $mform->registerNoSubmitButton($elementname); $mform->addElement('submit', $elementname, get_string('deletechoice', self::MOD_NAME)); $mform->insertElementBefore($mform->removeElement($elementname, false), self::CHOICE_PLACEHOLDER_IDENTIFIER); }