function set_data($question) { if (!empty($question->options->trueanswer)) { $trueanswer = $question->options->answers[$question->options->trueanswer]; $draftid = file_get_submitted_draft_itemid('trueanswer'); $answerid = $question->options->trueanswer; $text = $trueanswer->feedback; $question->correctanswer = $trueanswer->fraction != 0; $question->feedbacktrue = array(); $question->feedbacktrue['text'] = $trueanswer->feedback; $question->feedbacktrue['format'] = $trueanswer->feedbackformat; $question->feedbacktrue['text'] = file_prepare_draft_area($draftid, $this->context->id, 'question', 'answerfeedback', !empty($answerid) ? (int) $answerid : null, $this->fileoptions, $text); $question->feedbacktrue['itemid'] = $draftid; } if (!empty($question->options->falseanswer)) { $falseanswer = $question->options->answers[$question->options->falseanswer]; $draftid = file_get_submitted_draft_itemid('falseanswer'); $answerid = $question->options->falseanswer; $text = $falseanswer->feedback; $question->feedbackfalse = array(); $question->feedbackfalse['text'] = $falseanswer->feedback; $question->feedbackfalse['format'] = $falseanswer->feedbackformat; $question->feedbackfalse['text'] = file_prepare_draft_area($draftid, $this->context->id, 'question', 'answerfeedback', !empty($answerid) ? (int) $answerid : null, $this->fileoptions, $text); $question->feedbackfalse['itemid'] = $draftid; } parent::set_data($question); }
function set_data($question) { if (empty($question->name)) { $question->name = get_string("random", "quiz"); } parent::set_data($question); }
function set_data($question) { if (!empty($question->options) && !empty($question->options->answers)) { $answer = reset($question->options->answers); $question->feedback = $answer->feedback; } $question->penalty = 0; parent::set_data($question); }
function set_data($question) { if (!empty($question->options->trueanswer)) { $trueanswer = $question->options->answers[$question->options->trueanswer]; $question->correctanswer = $trueanswer->fraction != 0; $question->feedbacktrue = $trueanswer->feedback; $question->feedbackfalse = $question->options->answers[$question->options->falseanswer]->feedback; } parent::set_data($question); }
function set_data($question) { if (empty($question->name)) { $question->name = get_string("randomsamatch", "quiz"); } if (empty($question->questiontext)) { $question->questiontext = get_string("randomsamatchintro", "quiz"); } parent::set_data($question); }
function set_data($question) { if (!empty($question->options)) { $question->essay = $question->options->essay; $question->maxbytes = $question->options->maxbytes; if (!empty($question->options->answers)) { $answer = reset($question->options->answers); $question->feedback = $answer->feedback; } } $question->penalty = 0; parent::set_data($question); }
function set_data($question) { if (isset($question->id) and $question->id and $question->qtype and $question->questiontext) { foreach ($question->options->questions as $key => $wrapped) { // The old way of restoring the definitions is kept to gradually // update all multianswer questions if (empty($wrapped->questiontext)) { $parsableanswerdef = '{' . $wrapped->defaultgrade . ':'; switch ($wrapped->qtype) { case 'multichoice': $parsableanswerdef .= 'MULTICHOICE:'; break; case 'shortanswer': $parsableanswerdef .= 'SHORTANSWER:'; break; case 'numerical': $parsableanswerdef .= 'NUMERICAL:'; break; default: error("questiontype {$wrapped->qtype} not recognized"); } $separator = ''; foreach ($wrapped->options->answers as $subanswer) { $parsableanswerdef .= $separator . '%' . round(100 * $subanswer->fraction) . '%'; $parsableanswerdef .= $subanswer->answer; if (!empty($wrapped->options->tolerance)) { // Special for numerical answers: $parsableanswerdef .= ":{$wrapped->options->tolerance}"; // We only want tolerance for the first alternative, it will // be applied to all of the alternatives. unset($wrapped->options->tolerance); } if ($subanswer->feedback) { $parsableanswerdef .= "#{$subanswer->feedback}"; } $separator = '~'; } $parsableanswerdef .= '}'; // Fix the questiontext fields of old questions set_field('question', 'questiontext', addslashes($parsableanswerdef), 'id', $wrapped->id); } else { $parsableanswerdef = str_replace('&#', '&\\#', $wrapped->questiontext); } $question->questiontext = str_replace("{#{$key}}", $parsableanswerdef, $question->questiontext); } } parent::set_data($question); }
public function set_data($question) { if (isset($question->options) && is_array($question->options->answers)) { $answers = $question->options->answers; $default_values = array(); $key = 0; foreach ($answers as $answer) { $default_values['answer[' . $key . ']'] = $answer->answer; $default_values['fraction[' . $key . ']'] = $answer->fraction; $default_values['feedback[' . $key . ']'] = $answer->feedback; $key++; } $question = (object) ((array) $question + $default_values); } parent::set_data($question); }
function set_data($question) { if (isset($question->options)) { $subquestions = $question->options->subquestions; if (count($subquestions)) { $key = 0; foreach ($subquestions as $subquestion) { $default_values['subanswers[' . $key . ']'] = $subquestion->answertext; $default_values['subquestions[' . $key . ']'] = $subquestion->questiontext; $key++; } } $default_values['shuffleanswers'] = $question->options->shuffleanswers; $question = (object) ((array) $question + $default_values); } parent::set_data($question); }
function set_data($question) { if (isset($question->options)) { $answers = $question->options->answers; if (count($answers)) { $key = 0; foreach ($answers as $answer) { $default_values['answer[' . $key . ']'] = $answer->answer; $default_values['fraction[' . $key . ']'] = $answer->fraction; $default_values['feedback[' . $key . ']'] = $answer->feedback; $key++; } } $default_values['usecase'] = $question->options->usecase; $question = (object) ((array) $question + $default_values); } parent::set_data($question); }
function set_data($question) { if (isset($question->options)) { $answers = $question->options->answers; if (count($answers)) { $key = 0; foreach ($answers as $answer) { $default_values['answer[' . $key . ']'] = $answer->answer; $default_values['fraction[' . $key . ']'] = $answer->fraction; $default_values['feedback[' . $key . ']'] = $answer->feedback; $key++; } } $default_values['single'] = $question->options->single; $default_values['shuffleanswers'] = $question->options->shuffleanswers; $default_values['correctfeedback'] = $question->options->correctfeedback; $default_values['partiallycorrectfeedback'] = $question->options->partiallycorrectfeedback; $default_values['incorrectfeedback'] = $question->options->incorrectfeedback; $question = (object) ((array) $question + $default_values); } parent::set_data($question); }
function set_data($question) { $is_new = empty($question->id) || empty($question->options->rows); if (!$is_new) { $options = $question->options; $question->multiple = $options->multiple ? '1' : '0'; $question->grademethod = $options->grademethod; $question->rowshort = array(); $question->rowlong = array(); $question->rowfeedback = array(); $question->rowid = array(); foreach ($options->rows as $row) { $question->rowshort[] = $row->shorttext; $question->rowlong[] = $row->description; $question->rowfeedback[] = $row->feedback; $question->rowid[] = $row->id; } $question->colshort = array(); $question->collong = array(); $question->colid = array(); foreach ($options->cols as $col) { $question->colshort[] = $col->shorttext; $question->collong[] = $col->description; $question->colid[] = $col->id; } //$question->matrix = array(); $row_index = 0; foreach ($options->rows as $row) { $col_index = 0; foreach ($options->cols as $col) { $cell_name = qtype_matrix_grading::cell_name($row_index, $col_index, $options->multiple); $weight = $options->weights[$row->id][$col->id]; if ($options->multiple) { $value = $weight > 0 ? 'on' : ''; $question->{$cell_name} = $value; } else { if ($weight > 0) { $question->{$cell_name} = $col_index; break; } } $col_index++; } $row_index++; } } /* set data should be called on new questions to set up course id, etc * after setting up values for question */ parent::set_data($question); }
function set_data($question) { global $DB; $default_values = array(); if (isset($question->id) and $question->id and $question->qtype and $question->questiontext) { foreach ($question->options->questions as $key => $wrapped) { if (!empty($wrapped)) { // The old way of restoring the definitions is kept to gradually // update all multianswer questions if (empty($wrapped->questiontext)) { $parsableanswerdef = '{' . $wrapped->defaultgrade . ':'; switch ($wrapped->qtype) { case 'multichoice': $parsableanswerdef .= 'MULTICHOICE:'; break; case 'shortanswer': $parsableanswerdef .= 'SHORTANSWER:'; break; case 'numerical': $parsableanswerdef .= 'NUMERICAL:'; break; default: print_error('unknownquestiontype', 'question', '', $wrapped->qtype); } $separator = ''; foreach ($wrapped->options->answers as $subanswer) { $parsableanswerdef .= $separator . '%' . round(100 * $subanswer->fraction) . '%'; $parsableanswerdef .= $subanswer->answer; if (!empty($wrapped->options->tolerance)) { // Special for numerical answers: $parsableanswerdef .= ":{$wrapped->options->tolerance}"; // We only want tolerance for the first alternative, it will // be applied to all of the alternatives. unset($wrapped->options->tolerance); } if ($subanswer->feedback) { $parsableanswerdef .= "#{$subanswer->feedback}"; } $separator = '~'; } $parsableanswerdef .= '}'; // Fix the questiontext fields of old questions $DB->set_field('question', 'questiontext', $parsableanswerdef, array('id' => $wrapped->id)); } else { $parsableanswerdef = str_replace('&#', '&\\#', $wrapped->questiontext); } $question->questiontext = str_replace("{#{$key}}", $parsableanswerdef, $question->questiontext); } } } // set default to $questiondisplay questions elements if ($this->reload) { if (isset($this->questiondisplay->options->questions)) { $subquestions = fullclone($this->questiondisplay->options->questions); if (count($subquestions)) { $sub = 1; foreach ($subquestions as $subquestion) { $prefix = 'sub_' . $sub . '_'; // validate parameters $answercount = 0; $maxgrade = false; $maxfraction = -1; if ($subquestion->qtype == 'shortanswer') { switch ($subquestion->usecase) { case '1': $default_values[$prefix . 'usecase'] = get_string('caseyes', 'quiz'); break; case '0': default: $default_values[$prefix . 'usecase'] = get_string('caseno', 'quiz'); } } if ($subquestion->qtype == 'multichoice') { $default_values[$prefix . 'layout'] = $subquestion->layout; switch ($subquestion->layout) { case '0': $default_values[$prefix . 'layout'] = get_string('layoutselectinline', 'qtype_multianswer'); break; case '1': $default_values[$prefix . 'layout'] = get_string('layoutvertical', 'qtype_multianswer'); break; case '2': $default_values[$prefix . 'layout'] = get_string('layouthorizontal', 'qtype_multianswer'); break; default: $default_values[$prefix . 'layout'] = get_string('layoutundefined', 'qtype_multianswer'); } } foreach ($subquestion->answer as $key => $answer) { if ($subquestion->qtype == 'numerical' && $key == 0) { $default_values[$prefix . 'tolerance[' . $key . ']'] = $subquestion->tolerance[0]; } $trimmedanswer = trim($answer); if ($trimmedanswer !== '') { $answercount++; if ($subquestion->qtype == 'numerical' && !(is_numeric($trimmedanswer) || $trimmedanswer == '*')) { $this->_form->setElementError($prefix . 'answer[' . $key . ']', get_string('answermustbenumberorstar', 'qtype_numerical')); } if ($subquestion->fraction[$key] == 1) { $maxgrade = true; } if ($subquestion->fraction[$key] > $maxfraction) { $maxfraction = $subquestion->fraction[$key]; } } $default_values[$prefix . 'answer[' . $key . ']'] = htmlspecialchars($answer); } if ($answercount == 0) { if ($subquestion->qtype == 'multichoice') { $this->_form->setElementError($prefix . 'answer[0]', get_string('notenoughanswers', 'qtype_multichoice', 2)); } else { $this->_form->setElementError($prefix . 'answer[0]', get_string('notenoughanswers', 'quiz', 1)); } } if ($maxgrade == false) { $this->_form->setElementError($prefix . 'fraction[0]', get_string('fractionsnomax', 'question')); } foreach ($subquestion->feedback as $key => $answer) { $default_values[$prefix . 'feedback[' . $key . ']'] = htmlspecialchars($answer['text']); } foreach ($subquestion->fraction as $key => $answer) { $default_values[$prefix . 'fraction[' . $key . ']'] = $answer; } $sub++; } } } } $default_values['alertas'] = "<strong>" . get_string('questioninquiz', 'qtype_multianswer') . "</strong>"; if ($default_values != "") { $question = (object) ((array) $question + $default_values); } parent::set_data($question); }
function set_data($question) { if (isset($question->options)) { // added by Harry - beginn $default_values['arrangemedia'] = $question->options->arrangemedia; $default_values['placemedia'] = $question->options->placemedia; // added by Harry - end $default_values['backgroundmedia'] = $question->options->backgroundmedia->media; $default_values['globalfeedbackgrade'] = $question->options->feedbackfraction; $default_values['feedbackok'] = $question->options->feedbackok; $default_values['feedbackmissed'] = $question->options->feedbackmissed; $oldmedia = $question->options->media; if (count($oldmedia)) { $key = 0; $dbmediaids = array(); // maps the db ids of the dragdrop objects to the html slots $dbhsids = array(); // maps the db ids of the primary hot spots to the html slots foreach ($oldmedia as $omedia) { $default_values['ddtext[' . $key . ']'] = $omedia->questiontext; $default_values['ddmedia[' . $key . ']'] = $omedia->media; $default_values['ddmediatargetx[' . $key . ']'] = $omedia->targetx; $default_values['ddmediatargety[' . $key . ']'] = $omedia->targety; $default_values['ddmediadisplaywidth[' . $key . ']'] = $omedia->displaywidth; $default_values['ddmediadisplayheight[' . $key . ']'] = $omedia->displayheight; if ($omedia->primary_hotspot != 0) { $hotspot = $omedia->hotspots[$omedia->primary_hotspot]; $default_values['ddhotspotx[' . $key . ']'] = $hotspot->x; $default_values['ddhotspoty[' . $key . ']'] = $hotspot->y; $default_values['ddhotspotwidth[' . $key . ']'] = $hotspot->width; $default_values['ddhotspotheight[' . $key . ']'] = $hotspot->height; } else { $default_values['ddhotspotgroup[' . $key . '][ddhotspotx]'] = 0; $default_values['ddhotspotgroup[' . $key . '][ddhotspoty]'] = 0; $default_values['ddhotspotgroup[' . $key . '][ddhotspotwidth]'] = 0; $default_values['ddhotspotgroup[' . $key . '][ddhotspotheight]'] = 0; } $dbmediaids[$omedia->id] = $key + 1; $dbhsids[$omedia->primary_hotspot] = $key + 1; $key++; } // map the db ids to html "alternate hot spots" fields foreach ($dbmediaids as $dbmediaid => $htmlslot) { if (count($oldmedia[$dbmediaid]->hotspots) > 1) { $hotspotids = array(); foreach ($oldmedia[$dbmediaid]->hotspots as $id => $hs) { if ($id != $oldmedia[$dbmediaid]->primary_hotspot) { $hotspotids[] = $dbhsids[$id]; } } $hotspotids = implode(',', $hotspotids); $default_values['althotspots[' . ($htmlslot - 1) . ']'] = $hotspotids; } } } $question = (object) ((array) $question + $default_values); } parent::set_data($question); }
/** Patch up data from the database before a user edits it in the form. */ public function set_data($question) { if (!empty($question->questiontext)) { $question->questiontext = $this->convert_legacy_fact_sheets($question->questiontext); } if (!empty($question->generalfeedback)) { $question->generalfeedback = $this->convert_legacy_fact_sheets($question->generalfeedback); } if (!empty($question->specificfeedback)) { $question->specificfeedback = $this->convert_legacy_fact_sheets($question->specificfeedback); } if (!empty($question->prts)) { foreach ($question->prts as $prtname => $prt) { if (!empty($prt->nodes)) { foreach ($prt->nodes as $nodename => $node) { $node->truefeedback = $this->convert_legacy_fact_sheets($node->truefeedback); $node->falsefeedback = $this->convert_legacy_fact_sheets($node->falsefeedback); } } } } parent::set_data($question); }
function set_data($question) { $answer = $this->answer; $default_values = array(); if (count($answer)) { $key = 0; foreach ($answer as $answer) { $default_values['answer[' . $key . ']'] = $answer->answer; $default_values['fraction[' . $key . ']'] = $answer->fraction; $default_values['tolerance[' . $key . ']'] = $answer->tolerance; $default_values['tolerancetype[' . $key . ']'] = $answer->tolerancetype; $default_values['correctanswerlength[' . $key . ']'] = $answer->correctanswerlength; $default_values['correctanswerformat[' . $key . ']'] = $answer->correctanswerformat; $default_values['feedback[' . $key . ']'] = $answer->feedback; $key++; } } if (isset($question->options)) { $units = array_values($question->options->units); // make sure the default unit is at index 0 usort($units, create_function('$a, $b', 'if (1.0 === (float)$a->multiplier) { return -1; } else ' . 'if (1.0 === (float)$b->multiplier) { return 1; } else { return 0; }')); if (count($units)) { $key = 0; foreach ($units as $unit) { $default_values['unit[' . $key . ']'] = $unit->unit; $default_values['multiplier[' . $key . ']'] = $unit->multiplier; $key++; } } } $key = 0; $formdata = array(); $fromform = new stdClass(); //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. /* if(!empty($this->datasetdefs)){ $j = $this->noofitems * count($this->datasetdefs); for ($itemnumber = $this->noofitems; $itemnumber >= 1; $itemnumber--){ $data = array(); foreach ($this->datasetdefs as $defid => $datasetdef){ if (isset($datasetdef->items[$itemnumber])){ $formdata["number[$j]"] = $datasetdef->items[$itemnumber]->value; $formdata["definition[$j]"] = $defid; $formdata["itemid[$j]"] = $datasetdef->items[$itemnumber]->id; $data[$datasetdef->name] = $datasetdef->items[$itemnumber]->value; } $j--; } // echo "<p>answers avant comment <pre>";print_r($answer);echo"</pre></p>"; // echo "<p>data avant comment <pre>";print_r($data);echo"</pre></p>"; if($this->noofitems != 0 ) { 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=''; // echo "<p> comment <pre>";print_r($comment);echo"</pre></p>"; foreach ($this->nonemptyanswer as $key => $answer) { $totalcomment .= $comment->stranswers[$key].'<br/>'; } $formdata['answercomment['.$itemnumber.']'] = $totalcomment ; } } // $formdata['reload'] = '1'; // $formdata['nextpageparam[forceregeneration]'] = $this->regenerate; $formdata['selectdelete'] = '1'; $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){ $formdata["datasetdef[$idx]"] = $defid; $idx++; } $formdata = $this->qtypeobj->custom_generator_set_data($this->datasetdefs, $formdata); }*/ $question = (object) ((array) $question + $default_values + $this->formdata); parent::set_data($question); }
function set_data($question) { if (isset($question->options)) { $answers = $question->options->answers; if (count($answers)) { $key = 0; foreach ($answers as $answer) { $default_values['answer[' . $key . ']'] = $answer->answer; $default_values['fraction[' . $key . ']'] = $answer->fraction; $default_values['tolerance[' . $key . ']'] = $answer->tolerance; $default_values['tolerancetype[' . $key . ']'] = $answer->tolerancetype; $default_values['correctanswerlength[' . $key . ']'] = $answer->correctanswerlength; $default_values['correctanswerformat[' . $key . ']'] = $answer->correctanswerformat; $default_values['feedback[' . $key . ']'] = $answer->feedback; $key++; } } $units = array_values($question->options->units); // make sure the default unit is at index 0 usort($units, create_function('$a, $b', 'if (1.0 === (float)$a->multiplier) { return -1; } else ' . 'if (1.0 === (float)$b->multiplier) { return 1; } else { return 0; }')); if (count($units)) { $key = 0; foreach ($units as $unit) { $default_values['unit[' . $key . ']'] = $unit->unit; $default_values['multiplier[' . $key . ']'] = $unit->multiplier; $key++; } } } $default_values['submitbutton'] = get_string('nextpage', 'qtype_calculated'); $default_values['makecopy'] = get_string('makecopynextpage', 'qtype_calculated'); /* set the wild cards category display given that on loading the category element is unselected when processing this function but have a valid value when processing the update category button. The value can be obtain by $qu->category =$this->_form->_elements[$this->_form->_elementIndex['category']]->_values[0]; but is coded using existing functions */ $qu = new stdClass(); $el = new stdClass(); /* no need to call elementExists() here */ if ($this->_form->elementExists('category')) { $el = $this->_form->getElement('category'); } else { $el = $this->_form->getElement('categorymoveto'); } if ($value = $el->getSelected()) { $qu->category = $value[0]; } else { $qu->category = $question->category; // on load $question->category is set by question.php } $html2 = $this->qtypeobj->print_dataset_definitions_category($qu); $this->_form->_elements[$this->_form->_elementIndex['listcategory']]->_text = $html2; $question = (object) ((array) $question + $default_values); parent::set_data($question); }
function set_data($question) { if (isset($question->options)) { $answers = $question->options->answers; if (count($answers)) { $key = 0; foreach ($answers as $answer) { $default_values['answer[' . $key . ']'] = $answer->answer; $default_values['fraction[' . $key . ']'] = $answer->fraction; $default_values['tolerance[' . $key . ']'] = $answer->tolerance; $default_values['feedback[' . $key . ']'] = $answer->feedback; $key++; } } $units = array_values($question->options->units); if (!empty($units)) { foreach ($units as $key => $unit) { $default_values['unit[' . $key . ']'] = $unit->unit; $default_values['multiplier[' . $key . ']'] = $unit->multiplier; } } $question = (object) ((array) $question + $default_values); } parent::set_data($question); }
/** * Sets the existing values into the form for the question specific data. * It sets the answers before calling the parent function. * * @param $question the question object from the database being used to fill the form */ function set_data($question) { if (isset($question->options)) { global $QTYPES; $extras = $QTYPES[$this->qtype()]->subquestion_option_extras(); foreach ($extras as $extra) { $default_values[$extra] = $question->options->extra->{$extra}; } $show_tags = array('vars2', 'preunit', 'otherrule', 'subqtext', 'feedback'); foreach ($show_tags as $tag) { $is_show[$tag] = false; } if (count($question->options->answers)) { foreach ($question->options->answers as $key => $answer) { $tags = $QTYPES[$this->qtype()]->subquestion_answer_tags(); foreach ($tags as $tag) { $default_values[$tag . '[' . $key . ']'] = $answer->{$tag}; } foreach ($show_tags as $tag) { $is_show[$tag] = $is_show[$tag] || strlen(trim($answer->{$tag})) != 0; } } } foreach ($show_tags as $tag) { if ($is_show[$tag]) { $default_values['showoptions[' . $tag . ']'] = 1; } } $default_values['showoptions[correctnessraw]'] = 0; $question = (object) ((array) $question + $default_values); } parent::set_data($question); }
public function set_data($question) { /* accessing the form in this way is probably not correct style */ $this->_form->getElement('wronganswers')->setValue($this->get_wrong_answers($question)); parent::set_data($question); }
function set_data($question) { parent::set_data($question); }
/** * Sets the existing values into the form for the question specific data. * * This method copies the data from the existing database record into the form fields as default * values for the various elements. * * @param $question the question object from the database being used to fill the form */ function set_data($question) { // Check to see if there are any existing question options, if not then just call // the base class set data method and exit if (!isset($question->options)) { return parent::set_data($question); } // Our first job is to set the defaults for the answers. Start by getting the answers... $answers = $question->options->answers; // If we found any answers then loop over them using a numerical key to provide an index // to the arrays we need to access in the form if (count($answers)) { $key = 0; foreach ($answers as $answer) { // For every answer set the default values $default_values['answer[' . $key . ']'] = $answer->answer; $default_values['fraction[' . $key . ']'] = $answer->fraction; $default_values['feedback[' . $key . ']'] = $answer->feedback; $key++; } } // Now we do exactly the same for the variables... $vars = $question->options->variables; // If we found any answers then loop over them using a numerical key to provide an index // to the arrays we need to access in the form if (count($vars)) { $key = 0; foreach ($vars as $var) { // For every variable set the default values $default_values['variable[' . $key . ']'] = $var->name; // Only set the mon and max defaults if this variable has a range if ($var->min != '') { $default_values['varmin[' . $key . ']'] = $var->min; $default_values['varmax[' . $key . ']'] = $var->max; } $key++; } } // Add the default values for the allowed functions controls // First check to see if there are any allowed functions defined if (count($question->options->allowedfuncs) > 0) { // Clear the 'all functions' flag since functions are restricted $default_values['allowedfuncs[all]'] = 0; // Loop over all the functions which the parser understands foreach (qtype_algebra_parser::$functions as $func) { // For each function see if the function is in the allowed function // list and if so set the check box otherwise remove the check box if (in_array($func, $question->options->allowedfuncs)) { $default_values['allowedfuncs[' . $func . ']'] = 1; } else { $default_values['allowedfuncs[' . $func . ']'] = 0; } } } else { $default_values['allowedfuncs[all]'] = 1; } // Add the default values to the question object in a form which the parent // set data method will be able to use to find the default values $question = (object) ((array) $question + $default_values); // Finally call the parent set data method to handle everything else parent::set_data($question); }
function set_data($question) { if (!empty($question->id) && ($matrix = matrix_qtype::load_all_data($question->id))) { $question->multiple = $matrix->multiple; $question->grademethod = $matrix->grademethod; $question->renderer = $matrix->renderer; $question->rowshort = $matrix->rowshort; $question->rowlong = $matrix->rowlong; $question->rowfeedback = $matrix->rowfeedback; $question->colshort = $matrix->colshort; $question->collong = $matrix->collong; $question->rows = $matrix->rows; $question->cols = $matrix->cols; $question->rowid = array_keys($matrix->rows); $question->colid = array_keys($matrix->cols); $question->gradingmatrix = $matrix->gradingmatrix; } parent::set_data($question); }
function set_data($question) { if (isset($question->options)) { $answers = $question->options->answers; if (count($answers)) { $key = 0; foreach ($answers as $answer) { $default_values['answer[' . $key . ']'] = $answer->answer; $default_values['fraction[' . $key . ']'] = $answer->fraction; $default_values['tolerance[' . $key . ']'] = $answer->tolerance; $default_values['feedback[' . $key . ']'] = $answer->feedback; $key++; } } $units = array_values($question->options->units); // make sure the default unit is at index 0 usort($units, create_function('$a, $b', 'if (1.0 === (float)$a->multiplier) { return -1; } else ' . 'if (1.0 === (float)$b->multiplier) { return 1; } else { return 0; }')); if (count($units)) { if (abs($units[0]->multiplier - 1.0) > 1.0E-6) { $newunit = new stdClass(); $newunit->unit = ''; $newunit->multiplier = 1.0; $units = array_merge(array(0 => $newunit), $units); } $key = 0; foreach ($units as $unit) { $default_values['unit[' . $key . ']'] = $unit->unit; $default_values['multiplier[' . $key . ']'] = $unit->multiplier; $key++; } } $question = (object) ((array) $question + $default_values); } parent::set_data($question); }
/** * @desc Sets the data in the question object based on old form data. Do some tricks to get file managers to work. */ function set_data($question) { if (isset($this->question->webwork)) { $wwquestion = $this->question->webwork; //set fields to old values $question->code = $wwquestion->getCodeText(); $question->codecheck = $wwquestion->getCodeCheck(); } parent::set_data($question); }